diff options
| author | 2021-09-24 19:53:58 +0200 | |
|---|---|---|
| committer | 2021-09-24 19:53:58 +0200 | |
| commit | 650e739fbb66eb30502675cc3b8bd257e1ee825d (patch) | |
| tree | f5f2c1a9a7c1bc7b9bef90db088bc04746a74dd6 | |
| parent | Merge pull request #1843 from python-discord/fix-paste-site-inconsistency (diff) | |
Suppress NotFound for batch deletion.
I will copy my comment from the code, as it explains why we want this:
In the rare case where we found messages matching the spam filter across
multiple channels, it is possible that a single channel will only
contain a single message to delete. If that should be the case,
discord.py will use the "delete single message" endpoint instead of the
bulk delete endpoint, and the single message deletion endpoint will
complain if you give it that does not exist.  As this means that we have
no other message to delete in this channel (and message deletes work
per-channel), we can just log an exception and carry on with business.
| -rw-r--r-- | bot/exts/filters/antispam.py | 15 | 
1 files changed, 14 insertions, 1 deletions
| diff --git a/bot/exts/filters/antispam.py b/bot/exts/filters/antispam.py index 8c075fa95..72103c9fb 100644 --- a/bot/exts/filters/antispam.py +++ b/bot/exts/filters/antispam.py @@ -250,7 +250,20 @@ class AntiSpam(Cog):                  for message in messages:                      channel_messages[message.channel].append(message)                  for channel, messages in channel_messages.items(): -                    await channel.delete_messages(messages) +                    try: +                        await channel.delete_messages(messages) +                    except NotFound: +                        # In the rare case where we found messages matching the +                        # spam filter across multiple channels, it is possible +                        # that a single channel will only contain a single message +                        # to delete. If that should be the case, discord.py will +                        # use the "delete single message" endpoint instead of the +                        # bulk delete endpoint, and the single message deletion +                        # endpoint will complain if you give it that does not exist. +                        # As this means that we have no other message to delete in +                        # this channel (and message deletes work per-channel), +                        # we can just log an exception and carry on with business. +                        log.info(f"Tried to delete message `{messages[0].id}`, but message could not be found.")              # Otherwise, the bulk delete endpoint will throw up.              # Delete the message directly instead. | 
