Catches discord.NotFound in utils.mod.mass_purge (#3414)

* Catches `discord.NotFound` in `mass_purge`

* Create 3378.bugfix.rst
This commit is contained in:
Flame442 2020-01-20 14:09:17 -08:00 committed by Michael H
parent b085c1501f
commit 8f04fd436f
2 changed files with 7 additions and 5 deletions

View 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.

View File

@ -38,12 +38,13 @@ async def mass_purge(messages: List[discord.Message], channel: discord.TextChann
""" """
while messages: 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]) await channel.delete_messages(messages[:100])
messages = messages[100:] except discord.errors.HTTPException:
else: pass
await messages[0].delete() messages = messages[100:]
messages = []
await asyncio.sleep(1.5) await asyncio.sleep(1.5)