【问题标题】:How do I add a cooldown message to my code? [duplicate]如何在我的代码中添加冷却消息? [复制]
【发布时间】:2020-08-23 14:29:08
【问题描述】:
@client.command()
@commands.has_permissions(administrator=True)
@commands.cooldown(1, 60, commands.BucketType.user)
async def nuke(ctx, amount=500):
    await ctx.channel.purge(limit=amount + 1)
    await ctx.send(f'Channel has been Nuked!')


@nuke.error
async def nuke_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send('You do not have permissions to use this command!')

只是想知道如何为此添加冷却消息,说:“您必须等待 60 秒才能再次使用此命令!”

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    你可以使用

    if isinstance(error, commands.CommandOnCooldown):
        await ctx.send("You must wait 60 seconds before you can use this command again!")
    

    nuke_error 函数中。这将是工作。

    【讨论】:

    • 如果可行,您可以将其标记为答案。
    【解决方案2】:

    您可以使用它来发送错误以及剩余的秒数。

    @nuke.error
    async def nuke_cooldown(ctx, error):
        if isinstance(error, commands.CommandOnCooldown):
            await ctx.send(error)
    

    【讨论】:

      猜你喜欢
      • 2021-10-14
      • 1970-01-01
      • 2022-07-11
      • 2018-07-07
      • 2022-11-16
      • 1970-01-01
      • 2022-12-10
      • 2021-04-21
      • 2018-05-03
      相关资源
      最近更新 更多