【问题标题】:Command Cooldown - discord.py命令冷却 - discord.py
【发布时间】:2020-10-25 10:48:13
【问题描述】:

所以我对如何制作这样的功能进行了一些研究,这就是我想出的:

@bot.command()
@commands.cooldown(1, 30, commands.BucketType.user)
async def test(ctx):
    try:
        await ctx.send("Success")
    except commands.errors.CommandOnCooldown:
        await ctx.send("This command is on cooldown")

让机器人发送如下内容的最佳方法是什么: “您正在冷却,请在 26 秒后再试一次”?我试图在except commands.errors.CommandOnCooldown: 行中执行此操作,但这不起作用。

非常感谢任何帮助

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

    您可以使用Command.error()处理错误

    @bot.command()
    @commands.cooldown(1, 30, commands.BucketType.user)
    async def test(ctx):
        await ctx.send("Success")
    
    
    @test.error
    async def test_error(ctx, error):
        if isinstance(error, commands.CommandOnCooldown):
            await ctx.send(error)
    

    【讨论】:

      猜你喜欢
      • 2021-05-13
      • 2021-03-30
      • 2021-03-11
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 2021-04-25
      • 2021-05-20
      • 2019-02-17
      相关资源
      最近更新 更多