Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python discord.py机器人获得命令的剩余冷却时间_Python_Discord_Discord.py - Fatal编程技术网

Python discord.py机器人获得命令的剩余冷却时间

Python discord.py机器人获得命令的剩余冷却时间,python,discord,discord.py,Python,Discord,Discord.py,我正在开发一个基于python的discord机器人,它有以下命令 @client.command(name="Mine", description="Mine daily.", brief="Mine daily.", aliases=['mine', 'm'], pass_context=True) @commands.cooldown(1, 30, commands.BucketType.use

我正在开发一个基于python的discord机器人,它有以下命令

@client.command(name="Mine",
            description="Mine daily.",
            brief="Mine daily.",
            aliases=['mine', 'm'],
            pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def mine(ctx, arg):
   <content>
我想做的是让它获得剩余的冷却时间,并将其转换为可以在discord上对用户说的内容,例如“此命令为rate limited,请在28.58s后重试”

我在网上找不到太多的帮助,而且大部分都过时了或者似乎不起作用

谢谢

您需要为处理错误并发送消息的命令编写一个

@mine.error
async def mine_error(ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        msg = 'This command is ratelimited, please try again in {:.2f}s'.format(error.retry_after)
        await ctx.send(msg)
    else:
        raise error
您需要为处理错误并发送消息的命令编写一个

@mine.error
async def mine_error(ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        msg = 'This command is ratelimited, please try again in {:.2f}s'.format(error.retry_after)
        await ctx.send(msg)
    else:
        raise error

谢谢你的回答!我已经将这个命令与我的其他命令放在同一个级别上,但是不会在chat或shell中输出任何内容,尽管它确实会从shell中删除原始错误消息。我是否遗漏了其他内容?它需要在
mine
命令之后。您可以在处理程序中添加一个
print
,以查看执行是否使ti出现在那里吗?代码可以工作,但输出数字是20位小数,有没有办法缩短此长度?当然,将
“{}”
更改为
“{:.nf}”
,其中
n
是您想要的小数位数。我已经编辑了我的答案,为你的答案设置了n=2个库!我已经将这个命令与我的其他命令放在同一个级别上,但是不会在chat或shell中输出任何内容,尽管它确实会从shell中删除原始错误消息。我是否遗漏了其他内容?它需要在
mine
命令之后。您可以在处理程序中添加一个
print
,以查看执行是否使ti出现在那里吗?代码可以工作,但输出数字是20位小数,有没有办法缩短此长度?当然,将
“{}”
更改为
“{:.nf}”
,其中
n
是您想要的小数位数。我已将我的答案编辑为n=2