Skip to content Skip to sidebar Skip to footer

I Have A Error In Discord.py (purge Command)

I have this Python code for discord.py rewrite: @bot.command(pass_context=True) async def clean(ctx): if ctx.author.guild_permissions.administrator: llimit = ctx.me

Solution 1:

You can treat single argument callables (like int) like converters for the purpose of declaring arguments. I also changed your permissions check to be handled automatically by a commands.check

@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def clean(ctx, limit: int):
        await ctx.channel.purge(limit=limit)
        await ctx.send('Cleared by {}'.format(ctx.author.mention))
        await ctx.message.delete()

@clean.error
async def clear_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send("You cant do that!")

Solution 2:

The limit argument of the purge function takes an integer as a value

Try doing something like this

@bot.command(pass_context=True)asyncdefclean(ctx):
    if ctx.author.guild_permissions.administrator:
            llimit = ctx.message.content[10:].strip()
            await ctx.channel.purge(limit=int(llimit))
            await ctx.send('Cleared by <@{.author.id}>'.format(ctx))
        await ctx.message.delete()
else:
    await ctx.send("You cant do that!")

I'm not entirely sure what you're trying to accomplish with content[10:].strip() but if you're trying to ignore the !clean part of your command you are using too large of a number. content[7:] would suffice

Solution 3:

Also to make the bot check errors you can even do like this

@bot.command(pass_context=True)@commands.has_permissions(administrator=True)asyncdefclean(ctx, limit: int):
        await ctx.channel.purge(limit=limit)
        await ctx.send(f'Cleared by {ctx.author.mention}')
        await ctx.message.delete()

@bot.eventasyncdefon_command_error(ctx, error):
    ifisinstance(error, commands.MissingPermissions):
        await ctx.send("You cant do that!")

Also this way it will remove errors of every command so that will be better

Post a Comment for "I Have A Error In Discord.py (purge Command)"