Intermittent message.add_reaction() - 403 Forbidden (error code: 50013)
See original GitHub issueSummary
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:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
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.
Nope.