mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Catches discord.NotFound in utils.mod.mass_purge (#3414)
* Catches `discord.NotFound` in `mass_purge` * Create 3378.bugfix.rst
This commit is contained in:
parent
b085c1501f
commit
8f04fd436f
1
changelog.d/3378.bugfix.rst
Normal file
1
changelog.d/3378.bugfix.rst
Normal file
@ -0,0 +1 @@
|
||||
Fixed an error when ``redbot.core.utils.mod.mass_purge`` is passed ``COUNT % 100 == 1`` messages AND the last message in the list does not exist.
|
||||
@ -38,12 +38,13 @@ async def mass_purge(messages: List[discord.Message], channel: discord.TextChann
|
||||
|
||||
"""
|
||||
while messages:
|
||||
if len(messages) > 1:
|
||||
# discord.NotFound can be raised when `len(messages) == 1` and the message does not exist.
|
||||
# As a result of this obscure behavior, this error needs to be caught just in case.
|
||||
try:
|
||||
await channel.delete_messages(messages[:100])
|
||||
messages = messages[100:]
|
||||
else:
|
||||
await messages[0].delete()
|
||||
messages = []
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
messages = messages[100:]
|
||||
await asyncio.sleep(1.5)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user