【问题标题】:Does discord.py do that continously?discord.py 会持续这样做吗?
【发布时间】:2021-01-09 18:00:17
【问题描述】:

我正在尝试编写一个不和谐的机器人,但在学习模块时我被困在这里;

我的意思是在下面的代码中,每当在机器人有权访问的通道中发送消息时都会调用 on_message 函数,并且会在应用程序关闭之前不停地调用 on_reminder 函数吗?

这是我的代码;

@client.event
async def on_message(message):
    command_list={"!odev":command_odev,"!teslim":command_teslim,"!kontrol":command_kontrol}

    try:
        excep_src = "Geçersiz Komut!"
        msg2 = " "
        msg1 = " "
        if message.content.splitlines()[0].strip() not in command_list:
            raise Exception()

        msg1 = "Geçersiz girdi, lütfen komutu şu düzende belirtin:"
        excep_src=" "
        msg2=command_list[message.content.splitlines()[0].strip()]

        await message.channel.send(msg1)

    except:
        excep_src,msg1,msg2=excep_src,msg1,msg2

        await message.channel.send(f"""
{excep_src if 2 == len(excep_src.split()) else msg1}
{msg2}
            """)


## !odev yeni ödev verme
## !teslim ödev teslim etme
## !kontrol ödevi teslim edip etmediğini kontrol etme

@client.event
async def on_reminder():
    sleep(3600)
    kontrol()

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    你可以看看documentation:

    • discord.on_message(message) :“在创建和发送 Message 时调用”,因此只要在机器人有权访问的频道中发送消息,就会触发此事件。
    • 至于on_reminder,它不是现有事件,因此不会被触发。如果您希望它每小时运行一次,您可能需要使用 task 分机。

    【讨论】:

      猜你喜欢
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 2020-03-28
      • 1970-01-01
      • 2012-12-12
      • 2012-08-13
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多