首页 > 解决方案 > 如何在 Python 中为 Discord 机器人命令添加冷却时间?

问题描述

我正在尝试为 python 中的 Discord bot 命令添加冷却时间。我想要它,这样人们每分钟只能使用该命令一次,如果他们尝试更多地使用它,它将向他们发送一条消息,说明还剩多少时间。这是我当前的代码:

@client.command(pass_context=True)
@commands.cooldown(1, 60, commands.BucketType.user)
async def work(context):

你能告诉我这有什么问题吗?

标签: pythonpython-3.xdiscorddiscord.py

解决方案


您面临以下错误:

@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

推荐阅读