Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.92k stars 3.77k forks source link

[Glitch?] allowed_mentions ignored for short duration #9781

Open ItsCubeTime opened 7 months ago

ItsCubeTime commented 7 months ago

Core issue:

I havent been able to reproduce this, but this morning one of our Bots using discordpy mentioned @everyone with a message sent using the statements:

...
allowed_mentions = discord.AllowedMentions(everyone=False, users=True, roles=False,replied_user=True)

responsemsg = await message.reply(f"{prefix}{part}", allowed_mentions=allowed_mentions)

(Where f"{prefix}{part}" contained the substring "@everyone")

So far we havent been able to reproduce the issue, but 4 mentions was sent within a couple of minutes before the glitch seemed to go away on its own (as we were testing a couple of hours later, messages sent using the same code would not result in a ping, a lot of users in the server also tried to send more pings after the first ones were sent, but for some reason only 4 out of the pings actually resulted in a mention of @everyone

Additional Info:

The bot that exhibited the bug was an AI chatbot that would respond to user prompts - and around 20 users were essentially using it to try and spam everyone on the server for a couple of hours. Only 4 pings went through however.

In case its to any use, I have a time tracked log of all the user sent requests (filtered by messages containing the substring 'everyone'). It might give an idea as to when the glitch was active. AiPromptsAllMessagesToday.txt )

Our bot is running on: Python verson: 3.12.2 discordpy version: 2.3.2 (and some Linux based distro)

AbstractUmbra commented 7 months ago

Hello,

AllowedMentions are handled Discord side.

What I mean by this is that we only send the AllowedMentions object alongside the request to create the message (more on the parameters).

This means that parsing the message content for this and disallowing it is done on Discord's API side, not within d.py.

If your code is actually what you have shown then we have done everything we can for AllowedMentions in sending. I can't imagine the API will suddenly stop respecting this key in the payload so I would advise you to peer over your codebase for places that you respond and explicitly disallow it.

Alternative solutions are:

ItsCubeTime commented 7 months ago

Just a food for thought, would it be possible that some of the messages sent to discords API got cut-off - omitting the allowed_mentions flag (not that that would explain how 4 messages in a row were able to go through)?

And yes, we are now manually reading the respond string, removing any mentions ourselves

AbstractUmbra commented 7 months ago

Definitely not, they are part of a json body and the allowed_mentions key is separate.

I'd still recommend one of the alternate solutions over manual intervention, but that's up to you.

ItsCubeTime commented 7 months ago

Alright, thanks for taking the time @AbstractUmbra