📜  清除命令 discord.py - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:37.129000             🧑  作者: Mango

代码示例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!")