Uzzlius
Uzzlius

Reputation: 13

Discord.py throws error: to many arguments on purge()

Hi there, the following code is supposed to clear the channel. If the argument is a nomber, it is supposed to delete as many messages as specified. If the argument is all, it is supposed to delete all messages, and if you don't specifie an argument, it should delete 10 messages as default.

 @client.command()
    @commands.has_permissions(manage_messages=True)
    async def clear(ctx, amount=None):
        try:
            await ctx.channel.purge(limit=int(amount) + 1)
        except:
            if amount == 'all':
                await ctx.channel.purge()
                return
            await ctx.channel.purge(10)

however, Im getting the following error, if i do !clear without an argument:

Command raised an exception: TypeError: purge() takes 1 positional argument but 2 were given

error

Upvotes: 0

Views: 81

Answers (1)

LoahL
LoahL

Reputation: 2613

purge uses keyword arguments, so you have to write limit=10 instead of just 10, see the documentation

Upvotes: 0

Related Questions