You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the purge method uses single-delete mode it can fail the entire method on missing messages
Reproduction Steps
Initiate a purge of messages with bulk=False or have it automatically fall back to the single delete strategy.
Manually delete one of the messages marked for purge before the method finishes.
Minimal Reproducible Code
importdatetimefromdiscord.extimportcommands# Post several messages, call this command, then manually delete a message while it is running.@commands.command()asyncdefpurge_test(ctx, minutes: int=10)
after_time=datetime.datetime.now() -datetime.timedelta(minutes=minutes)
defpurge_check(message):
return (message.author.id==ctx.author.id) and (message.channel.id==ctx.channel.id)
# bulk is set to False here to force the behavior but this can occur with bulk=Truereturnawaitctx.channel.purge(limit=None, reason='test', after=after_time, bulk=False)
Expected Results
Purge to continue gracefully after encountering a missing message, or defer errors raised until the rest of the purge is completed.
Actual Results
discord.errors.NotFound is raised and the purge terminates early, even if the error is handled.
Traceback:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10008): Unknown Message
Traceback (most recent call last):
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped
ret = await coro(*args, **kwargs)
File "/home/thero/sinbot/cogs/messagelogging.py", line 517, in clear
to_log = (await channel.purge(limit=None, check=purge_check, after=earliest_time, reason=f"Clear command invoked by {ctx.author.display_name}."))
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/channel.py", line 531, in purge
return await discord.abc._purge_helper(
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/abc.py", line 152, in _purge_helper
await strategy(to_delete, reason=reason)
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/abc.py", line 124, in _single_delete_strategy
await m.delete()
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/message.py", line 859, in delete
await self._state.http.delete_message(self.channel.id, self.id)
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/http.py", line 741, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
await ctx.command.invoke(ctx)
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1029, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
File "/home/thero/sinbot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 244, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInv
okeError: Command raised an exception: NotFound: 404 Not Found (error code: 10008): Unknown Message
Intents
members, presences, message_content
System Information
Python v3.10.12-final
discord.py v2.3.2-final
aiohttp v3.9.5
system info: Linux 5.15.0-101-generic fix typo #111-Ubuntu SMP Tue Mar 5 20:16:58 UTC 2024
Checklist
I have searched the open issues for duplicates.
I have shown the entire traceback, if possible.
I have removed my token from display, if visible.
Additional Context
This was encountered in the wild without forcing bulk=False in the purge method, I believe it was triggered because it was iterating channels to clear a user's messages entirely and they had a single message in a channel, which was deleted separately while the bot was running its cleanup command.
This particular case can be error-handled in a cleanup command easily, but I believe it is possible for this to happen in much more annoying ways such as a purge running into a message > 14 days old that is deleted before it can complete.
If you are trying to collect the results of a purge and this happens I cannot think of a good way to handle it, as some messages will be deleted but never get returned.
The text was updated successfully, but these errors were encountered:
Summary
If the purge method uses single-delete mode it can fail the entire method on missing messages
Reproduction Steps
Minimal Reproducible Code
Expected Results
Purge to continue gracefully after encountering a missing message, or defer errors raised until the rest of the purge is completed.
Actual Results
discord.errors.NotFound is raised and the purge terminates early, even if the error is handled.
Traceback:
Intents
members, presences, message_content
System Information
Checklist
Additional Context
This was encountered in the wild without forcing bulk=False in the purge method, I believe it was triggered because it was iterating channels to clear a user's messages entirely and they had a single message in a channel, which was deleted separately while the bot was running its cleanup command.
This particular case can be error-handled in a cleanup command easily, but I believe it is possible for this to happen in much more annoying ways such as a purge running into a message > 14 days old that is deleted before it can complete.
If you are trying to collect the results of a purge and this happens I cannot think of a good way to handle it, as some messages will be deleted but never get returned.
The text was updated successfully, but these errors were encountered: