goose.mp4
goose.mp4

Reputation: 272

Discord.py: Purge command raising CommandError

For whatever reason, 2 weeks later my completely untouched code for my purge command in my bot stopped working. Upon inspecting it, there seems to be absolutely nothing wrong with it.

Here is what I have:

@commands.cooldown(1, 10, commands.BucketType.user)
@commands.has_permissions(manage_messages=True)
@commands.command(aliases=['Purge', 'delete', 'del', 'clear', 'clr'])
async def purge(self, ctx, amount):
  limit = amount # amount you're deleting
  await ctx.channel.purge(limit=limit+1) # uses the argument for the amount to actually delete the messages
  await ctx.send(str(amount) + " messages have been deleted.", delete_after=5.0) # sends how many messages were deleted

Upvotes: 0

Views: 313

Answers (1)

Bagle
Bagle

Reputation: 2346

Your problem is that channel.purge() takes an int. One way you can solve this problem is by immediately converting the author's amount argument into an int (as seen in the short example below).

@commands.command()
async def purge(self, ctx, amount:int):
    await ctx.channel.purge(amount=amount+1)

Upvotes: 1

Related Questions