question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intermittent message.add_reaction() - 403 Forbidden (error code: 50013)

See original GitHub issue

Summary

Sometimes my bot gets 403 errors when trying to add reactions to messages.

Reproduction Steps

It comes up in my logs sometimes. I haven’t been able to figure out why.

Minimal Reproducible Code

import discord


def bot_can_react(message: discord.Message) -> bool:
    if message.channel.type == discord.ChannelType.private:
        return True
    
    perms = message.channel.guild.me.permissions_in(message.channel)
    
    return (
        perms.read_message_history and 
        perms.read_messages and
        perms.add_reactions and
        perms.manage_messages
    )


class Bot(discord.Client):
    async def on_message(self, message: discord.Message) -> None:
        if bot_can_react(message):
            message.add_reaction("✅")

Expected Results

The bot should react to messages with a ✅ emoji.

Actual Results

99% of the time this seems to work fine. Sometimes I get the 403 error 🤷🏻‍♀️

May 09 14:09:53 app/web.1 [2021-05-09 21:09:53][spellbot.operations][ERROR] - warning: discord (guild 841042902037823498): could not react to message: 403 Forbidden (error code: 50013): Missing Permissions
May 09 14:09:53 app/web.1 Traceback (most recent call last):
May 09 14:09:53 app/web.1   File "/usr/local/lib/python3.9/site-packages/spellbot/operations.py", line 133, in safe_react_emoji
May 09 14:09:53 app/web.1     await message.channel.send(s("reaction_permissions_required"))
May 09 14:09:53 app/web.1   File "/usr/local/lib/python3.9/site-packages/discord/abc.py", line 1065, in send
May 09 14:09:53 app/web.1     data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
May 09 14:09:53 app/web.1   File "/usr/local/lib/python3.9/site-packages/discord/http.py", line 248, in request
May 09 14:09:53 app/web.1     raise Forbidden(r, data)
May 09 14:09:53 app/web.1 discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

Intents

32511

System Information

  • Python v3.8.8-final
  • discord.py v1.7.1-final
  • aiohttp v3.7.4.post0
  • system info: Darwin 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

My main question is if I have the bot_can_react() function implemented correctly here. If it’s a private channel I just assume that I have the permissions because AFAIK there’s no way to tell? At least, I dug through the documentation and I couldn’t find a way.

Otherwise I use message.channel.guild.me.permissions_in() to ensure that I have all the following permissions:

  • read-message-history
  • read-messages
  • add-reactions
  • manage-messages

That should be good, right? Are there other permissions that I need to check here? Is there a way to check permissions for Direct Messages that I’m missing?

I just don’t know why I am seeing 403 errors here. It seems like it shouldn’t be possible.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Rapptzcommented, May 9, 2021

Yeah when this was introduced we library developers were against 400s/403s counting as spam for this reason but the Discord developers thought we were over-exaggerating the issue.

1reaction
Rapptzcommented, May 9, 2021

Is there some way to know if I am blocked by the user before attempting the add_reaction() call?

Nope.

Read more comments on GitHub >

github_iconTop Results From Across the Web

50013): Missing Permissions] My bot is unable to ban/kick ...
[403 Forbidden (error code: 50013): Missing Permissions] My bot is unable to ban/kick even with the highest priority role, and every single ...
Read more >
How to Fix a 403 Forbidden Error on Your WordPress Site
The 403 (Forbidden) status code indicates that the server understood the request but refuses to authorize it. A server that wishes to make ......
Read more >
Missing permissions, code 50013 - Discord - Community - uMod
[Discord Extension] An error occured whilst submitting a request to ... /messages/655722042561134612 (code Forbidden): {"message": "Missing Permissions", ...
Read more >
Troubleshoot API Gateway 403 Forbidden errors with Lambda ...
Look for an error message similar to one of the following. Example error message for Lambda authorizer functions that return an IAM policy ......
Read more >
403 Forbidden Error: What It Is and How to Fix It - Airbrake Blog
The 403 Forbidden Error is an HTTP response status code that indicates an identified client does not have proper authorization to access the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found