python - 如何在 Python 中为 Discord 机器人命令添加冷却时间?
问题描述
我正在尝试为 python 中的 Discord bot 命令添加冷却时间。我想要它,这样人们每分钟只能使用该命令一次,如果他们尝试更多地使用它,它将向他们发送一条消息,说明还剩多少时间。这是我当前的代码:
@client.command(pass_context=True)
@commands.cooldown(1, 60, commands.BucketType.user)
async def work(context):
你能告诉我这有什么问题吗?
解决方案
您面临以下错误:
@client.command(pass_context=True)
@commands.cooldown(1, 60, commands.BucketType.user)
async def work(context):
错误name 'commands' is not definied
意味着您需要导入其他模块。
from discord.ext import commands
推荐阅读
- machine-learning - PyTorch ConvNet 随机学习单个标签并卡住
- java - 来自@Transactional 方法的Spring @Async 方法调用在同一服务中时不是异步的
- python - IndentationError:意外缩进 321
- excel - Private Sub Worksheet_Change 结合两个代码
- python - 在 tensorflow 急切模式下调用 python 代码的开销很大
- microsoft-graph-api - Microsoft Graph 批处理查询:引用批处理依赖项字段
- javascript - 无法安装 Kepler React - TypeScript
- html - 设置最大高度会影响 z-index
- python - 未嵌套 DataFrame 列表
- machine-learning - Is it possible to fine-tune BERT to do retweet prediction?