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
Run the minimum code with a given token, debug guild, etc...
Create a new thread under some text channel in one of the debug guilds. Type a few random messages in this new thread. Run /purging_thread with the test_bot. There should be an error seen in actual results
Minimal Reproducible Code
#!/usr/bin/env python3importdiscordfromdiscord.extimportcommandsclassDeleteCog(commands.Cog):
def__init__(self, bot: commands.bot):
self.bot=bot@commands.slash_command(name="purging_thread",description="Deletes all messages from this bot in a thread.", )asyncdefpurging_thread(self, ctx):
awaitctx.channel.purge(limit=5)
if__name__=="__main__":
guilds= [...]
token="..."bot=discord.Bot(debug_guilds=guilds)
bot.add_cog(DeleteCog(bot))
bot.run(token)
Expected Results
Messages in the thread to be deleted.
Actual Results
Ignoring exception in command purging_thread:
Traceback (most recent call last):
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/commands/core.py", line 122, in wrapped
ret = await coro(arg)
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/commands/core.py", line 825, in _invoke
await self.callback(self.cog, ctx, **kwargs)
File "/home/user/git/discord_ui_testing/./testing.py", line 18, in purging_thread
await ctx.channel.purge(limit=5)
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/threads.py", line 475, in purge
return await _purge_messages_helper(
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/abc.py", line 169, in _purge_messages_helper
await strategy(to_delete, reason=reason)
TypeError: delete_messages() got an unexpected keyword argument 'reason'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/bot.py", line 1098, in invoke_application_command
await ctx.command.invoke(ctx)
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/commands/core.py", line 331, in invoke
await injected(ctx)
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/commands/core.py", line 128, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: delete_messages() got an unexpected keyword argument 'reason'
One of the helpers on Discord mentioned that if you go to venv/lib/python3.9/site-packages/discord/threads.py, and change line 354 to async def delete_messages(self, messages: Iterable[Snowflake], *, reason: Optional[str] = None) -> None:
It might fix the issue. I tested their fix and it does fix it.
The text was updated successfully, but these errors were encountered:
Summary
ctx.channel.purge does not work as expected in threads with version b7
Reproduction Steps
Install pycord b7 (also ensure Discord is uninstalled):
pip install -U py-cord==2.0.0b7
Run the minimum code with a given token, debug guild, etc...
Create a new thread under some text channel in one of the debug guilds. Type a few random messages in this new thread. Run /purging_thread with the test_bot. There should be an error seen in actual results
Minimal Reproducible Code
Expected Results
Messages in the thread to be deleted.
Actual Results
Ignoring exception in command purging_thread:
Traceback (most recent call last):
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/commands/core.py", line 122, in wrapped
ret = await coro(arg)
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/commands/core.py", line 825, in _invoke
await self.callback(self.cog, ctx, **kwargs)
File "/home/user/git/discord_ui_testing/./testing.py", line 18, in purging_thread
await ctx.channel.purge(limit=5)
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/threads.py", line 475, in purge
return await _purge_messages_helper(
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/abc.py", line 169, in _purge_messages_helper
await strategy(to_delete, reason=reason)
TypeError: delete_messages() got an unexpected keyword argument 'reason'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/bot.py", line 1098, in invoke_application_command
await ctx.command.invoke(ctx)
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/commands/core.py", line 331, in invoke
await injected(ctx)
File "/home/user/.pyenv/versions/bot_dev/lib/python3.9/site-packages/discord/commands/core.py", line 128, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: delete_messages() got an unexpected keyword argument 'reason'
Intents
All
System Information
Checklist
Additional Context
One of the helpers on Discord mentioned that if you go to venv/lib/python3.9/site-packages/discord/threads.py, and change line 354 to
async def delete_messages(self, messages: Iterable[Snowflake], *, reason: Optional[str] = None) -> None:
It might fix the issue. I tested their fix and it does fix it.
The text was updated successfully, but these errors were encountered: