【问题标题】:(discord.py) Make Bot only react to on_message() every x seconds(discord.py) 让 Bot 每 x 秒只对 on_message() 做出反应
【发布时间】:2020-10-31 21:12:58
【问题描述】:


我想让我的 Discord 机器人能够告诉用户在他们迟到时去睡觉,我正在这样做:

@client.event
async def on_message(message):
    now = datetime.datetime.now()
    now_hour = now.hour                                      #Gets current time in hours.
    if message.author != client.user and now_hour<6:        #Runs if the message is not sent by the bot or if the time is between 00:00 and 06:00
        await message.channel.send('Are you still awake? You ought to go to bed immediately!')
    await client.process_commands(message)                   #If not included, on_message() will override commands

但目前它会回复该时间段内的每条消息,这很烦人。我知道命令有冷却时间,但我无法为事件找到类似的东西。
所以我的问题是:是否有相当于事件的冷却时间,或者其他聪明的方法?

在此先感谢,对于我应该犯的新手错误,我们深表歉意。

【问题讨论】:

  • 你可能会找到答案here

标签: python discord.py


【解决方案1】:

是的,聪明的方法是使用数据库来存储用户信息和他们发送的最后一条消息。然后你计算保存到当前时间的时间,如果保存的时间超过了一定的时间,就告诉他们去睡觉。

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 2018-02-18
    • 2020-12-07
    • 2021-07-09
    • 1970-01-01
    • 2020-11-07
    • 2021-03-25
    • 2019-06-07
    • 2020-12-07
    相关资源
    最近更新 更多