命令冷却-discord.py

时间:2020-10-25 00:24:45

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

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

@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:行中执行此操作,但这不起作用。

任何帮助表示赞赏

1 个答案:

答案 0 :(得分: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)