【发布时间】:2021-10-14 03:06:18
【问题描述】:
以下代码工作正常,但我想添加一个等待时间,以便代码在设定的时间段内只工作一次然后重置。
例如,如果有人发消息“你好”,我希望机器人回复。但是,如果有人在 20 秒后发送“你好”消息,我希望机器人在给定时间(比如 2 分钟)内忽略该消息和任何其他“你好”消息。
@bot.event
async def on_message(message):
if bot.user == message.author:
return
if any(word in message.content.lower() for word in hello_message):
await message.channel.send(random.choice(hello_response))
【问题讨论】:
-
用你最后一次触发的时间戳存储一个变量,并检查最后一个是否超过 2 分钟前
-
如果您使用命令很容易,因为您可以在这里从一个命令到另一个命令的时间,您需要听我上面的人的意见,只需使用日期时间或任何带有时间戳的东西
标签: python discord discord.py