如何在代码中添加冷却时间消息?

时间:2020-08-22 01:51:44

标签: python discord discord.py

@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秒才能再次使用此命令!”

2 个答案:

答案 0 :(得分:-1)

您可以使用

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

。这会起作用。

答案 1 :(得分:-1)

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

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