Discord Python Bot-修复清除命令

时间:2021-05-03 13:21:42

标签: python list discord bots embed

我的机器人有一个命令可以清除几个单词或所有内容...

这是我的代码:

@bot.command(aliases=['c'])
@commands.has_permissions(manage_messages=True)
async def clear(ctx, amount: int = None):
    if amount == 0:
        await ctx.channel.purge(limit=10000000000000000000000)
        await ctx.send("Cleared the entire chat!")
        print("Cleared the chat!")
    else:
        await ctx.channel.purge(limit=amount)
        await ctx.send("Done!")
        print(f"Cleared {amount} messages!")

但如果我只写 >clear 它会清除所有内容...我怎么说,它不会清除任何内容或在 >clear 处说“输入金额”? 感谢帮助

1 个答案:

答案 0 :(得分:0)

好的修复它...

@bot.command(aliases=['c'])
@commands.has_permissions(manage_messages=True)
async def clear(ctx, amount: int = None):
    if amount == 0:
        await ctx.channel.purge(limit=10000000000000000000000)
        await ctx.send("Cleared the entire chat!")
        print("Cleared the chat!")
    else:
        if amount >= 1:
            await ctx.channel.purge(limit=amount)
            await ctx.send("Done!")
            print(f"Cleared {amount} messages!")

        else:
            return