被某人discord.py使用后,命令每x秒工作一次

2024-03-29 04:58:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一个带有on_消息的机器人,在有人使用它后,它每20秒工作一次。例如,如果我写!您好,20秒内任何人都不能使用该命令。 我开始编写但不知道如何完成的代码:

@bot.event
async def on_message(message):
    if message.content.startswith('!hello'):
        await message.channel.send('hi')

Tags: 代码命令event消息messagehelloasyncif
2条回答

你在找这个吗

#time in seconds.
@commands.cooldown(1, int(time), commands.cooldowns.BucketType.guild)

Source

似乎从here可以简单地将标准cooldown效果修改为整个server,而不仅仅是user

@commands.cooldown(1, 30, commands.BucketType.guild)
  • 1代表一次使用
  • 30代表30秒
  • 对于最后一个参数,您可以使用default、channel或guild分别创建全局、channel或server ratelimit

相关问题 更多 >