Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctx.channel.purge does not behave as expected in threads with version b7 #1252

Closed
3 tasks done
challos opened this issue Apr 11, 2022 · 0 comments · Fixed by #1253
Closed
3 tasks done

ctx.channel.purge does not behave as expected in threads with version b7 #1252

challos opened this issue Apr 11, 2022 · 0 comments · Fixed by #1253
Labels
bug Something isn't working

Comments

@challos
Copy link

challos commented Apr 11, 2022

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

#!/usr/bin/env python3
import discord
from discord.ext import commands

class DeleteCog(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.",
    )
    async def purging_thread(self, ctx):
        await ctx.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'

Intents

All

System Information

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

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.

@challos challos added the unconfirmed bug A bug report that needs triaging label Apr 11, 2022
jab416171 added a commit to jab416171/pycord that referenced this issue Apr 11, 2022
jab416171 added a commit to jab416171/pycord that referenced this issue Apr 11, 2022
jab416171 added a commit to jab416171/pycord that referenced this issue Apr 11, 2022
@Middledot Middledot added bug Something isn't working and removed unconfirmed bug A bug report that needs triaging labels Apr 11, 2022
@Middledot Middledot linked a pull request Apr 11, 2022 that will close this issue
7 tasks
Middledot added a commit that referenced this issue Apr 11, 2022
Add reason to delete_messages, fixes #1252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants