python - 冷却错误时如何在 discord.py 命令中将秒转换为分钟或小时
问题描述
@client.event
async def on_command_error(ctx,error):
if isinstance(error , commands.CommandOnCooldown):
await ctx.send(f'{ctx.author.mention}**hold your horses buddy <:iac_namaste:841266597318361098>**')
await ctx.send('Try again in {:2f}s'.format(error.retry_after))
我在我的一个命令上添加了 20 分钟的冷却时间
@commands.cooldown(1 , 1200, type=commands.BucketType.user)
它工作正常,但我没有得到 min 或 hr 格式的输出
我希望它在 20 分钟内发送类似 try again 之类的信息,并显示还剩多少分钟
解决方案
最好的方法是只使用新的不和谐时间戳格式
import time # Add this to the top
# Then in the error handler
await ctx.send('Try again in <t:{}:R>'.format(int(time.time() + error.retry_after)))
推荐阅读
- ios - 在 Highchart iOS 中,同一 y 轴上的两个 SPLine 无法正确显示
- c# - 如何创建“/
/{id1}/ /{id2}" 剃须刀页面中的此类路线? - ajax - Google 跟踪代码管理器中的代码触发,但未显示 - AJAX 网站
- android - 如何使用retrofit2 发布一个json 数组?例如,
- r - 侧边栏面板的R闪亮文本滚动
- hadoop - 长期运行应用程序的 YARN Kerberos 问题
- javascript - 语法错误 Javascript foreach
- r - 使用 read.table 导入文本文件时出错:引用字符串中的 EOF
- python-3.x - 当列值满足特定条件时,在 panda 数据帧的行中提取 2 列数据
- javascript - 对象未按预期呈现