python - 命令冷却数小时和数分钟
问题描述
我添加了一个命令冷却时间,但如何让它持续数小时和数分钟。
@bot.command(pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def ping(ctx):
msg = "Pong {0.author.mention}".format(ctx.message)
await bot.say(msg)
解决方案
commands.cooldown
的第二个参数,per
以秒为单位,您可以通过乘以它们的等效秒数(1 分钟 = 60 秒,1 小时 = 3600 秒)轻松地将所需的小时和分钟转换为秒。您还可以创建一个包装函数来为您进行转换:
def cooldown(rate, per_sec=0, per_min=0, per_hour=0, type=commands.BucketType.default):
return commands.cooldown(rate, per_sec + 60 * per_min + 3600 * per_hour, type)
@bot.command(pass_context=True)
@cooldown(1, per_min=5, per_hour=1, type=commands.BucketType.user)
async def ping(ctx):
msg = "Pong {0.author.mention}".format(ctx.message)
await bot.say(msg)
这将启动 1 小时 5 分钟的冷却时间。
推荐阅读
- html - 引导表内容未在每一行中对齐
- python - 在 pandas 中以不对称的时间段重新采样(8 个月然后 4 个月)
- c++ - 如何让用户在tinyxml2中输入xml文件的路径
- mongodb - 中止 mongo shell 命令(作为无限循环)而不结束 shell 本身
- python - 在 WSL 中使用 buildozer 创建 kivy android 包
- python - 我将如何获得 JSON 中具有最高(子?)值的行?(Python)
- android - 长时间未动的工作代码,突然抛出 NullPointerException
- python-3.x - 在 3d 索引的 rtree (python) 中,如何在树中创建子节点以及如何查询它们?
- mqtt - mosquitto ACL 限制客户端
- html - 页面加载时,关键帧动画在 Inner-Div 上不起作用