繁体   English   中英

Discord Python 机器人修复清除命令

[英]Discord Python Bot- fixing clear command

我的 Bot 有一个命令可以清除一些单词或所有内容...

这是我的代码:

@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 处说“输入金额”? 感谢您的帮助

好的修复它...

@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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM