【问题标题】:How do you add a cooldown for a Discord bot command in Python?如何在 Python 中为 Discord 机器人命令添加冷却时间?
【发布时间】:2019-06-28 20:16:35
【问题描述】:

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

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

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

【问题讨论】:

  • 你有什么问题?您是否看到错误消息?是否允许用户更频繁地使用命令而不是每分钟一次?您只是错过了剩余时间的消息吗?
  • 为什么我的帖子被删除了
  • @RandomChannel 如果您认为此问题与另一个问题重复,则应将其标记为重复。复制其他用户的答案,即使注明出处也是不允许的。
  • 我收到以下错误消息:NameError: name 'commands' is not defined
  • @MeowNerd 你需要从 discord.ext 导入命令

标签: python python-3.x discord discord.py


【解决方案1】:

您面临以下错误:

@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

【讨论】:

    猜你喜欢
    • 2021-09-07
    • 2022-12-10
    • 2019-02-19
    • 2017-11-21
    • 2017-07-08
    • 2018-02-15
    • 1970-01-01
    • 2017-09-08
    • 2018-06-26
    相关资源
    最近更新 更多