【问题标题】:How to add a command delay using the 'on_message' event - Discord.py如何使用“on_message”事件添加命令延迟 - Discord.py
【发布时间】:2020-08-17 16:31:54
【问题描述】:

我正在使用一个

@client.event
async def on_message(message):

对于我在我的不和谐机器人中的命令,有没有办法可以在命令使用之间添加延迟。例如,使用命令之间有 5 秒的延迟,如果用户在冷却期间尝试使用命令,机器人将向他们发送一条消息,说明还有多长时间的延迟。如果可能的话,每个命令是否会有单独的延迟? 非常感谢任何帮助。

【问题讨论】:

  • 这归结为在内存中拥有一个巨大的 json 文件、一个大型 SQL 数据库或一个字典,从而节省了每个用户的冷却时间。

标签: python discord.py


【解决方案1】:

您可以使用commands.cooldown 来实现冷却:

from discord.ext import commands

bot = commands.Bot("!")

@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
@bot.command()
async def example(ctx):
    await ctx.send("Command received ")

bot.run("token")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 2021-07-09
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多