命令冷却时间discord.py

2024-06-16 11:25:44 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我做了一些关于如何制作这样一个功能的研究,这就是我想到的:

@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")

让bot发送以下内容的最佳方式是: “您正在冷却,请在26秒后重试”?我试图在except commands.errors.CommandOnCooldown:行中执行此操作,但不起作用

非常感谢您的帮助


Tags: 功能sendasyncdefbotawaitcommandcommands
1条回答
网友
1楼 · 发布于 2024-06-16 11:25:44

您可以使用^{}处理错误

@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)

相关问题 更多 >