【发布时间】:2021-05-20 03:18:37
【问题描述】:
我没有在哪里问,所以我会在这里问。 (对不起,如果这是一个重复的问题或任何东西)。
我有一个命令,我想每 2 小时使用一次,我已经完成了,但是冷却时间错误是我的问题。我想将其格式化为:1 小时 30 分钟。我试过这个,但它以分钟为单位,以秒为单位。
@command.error
async def command_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown):
cd = round(error.retry_after)
hours = str(cd // 3600)
minutes = str(cd % 60)
await ctx.send(f'You can use this command again in {hours} hour(s), {minutes} minute(s)')
我也试过了,但它会显示 1.0 小时 30.0 分钟:
@command.error #thats the name of my command
async def command_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown):
m, s = divmod(error.retry_after, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 60)
await ctx.send(f'You can use this command again in {h} hour(s), {m} minute(s)')
有人知道解决方法吗?任何帮助表示赞赏:)
【问题讨论】:
标签: python discord discord.py bots