diff options
| author | 2021-09-25 01:52:39 +0200 | |
|---|---|---|
| committer | 2021-09-25 01:52:39 +0200 | |
| commit | 57088188edb378f2314a35a7546bfac70f9e3c7e (patch) | |
| tree | f5f2c1a9a7c1bc7b9bef90db088bc04746a74dd6 | |
| parent | Merge pull request #1843 from python-discord/fix-paste-site-inconsistency (diff) | |
| parent | Suppress NotFound for batch deletion. (diff) | |
Merge pull request #1846 from python-discord/suppress-notfound-messages-on-delete
Suppress NotFound for batch deletion.
| -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. | 
