【问题标题】:How to send message without @client.event in discord.py?如何在 discord.py 中发送没有@client.event 的消息?
【发布时间】:2022-10-07 23:05:03
【问题描述】:

我需要一种方法来不断检查 discord.py 中的消息 'kill'。我的代码中有很多 while 循环,所以我需要使用 threading 模块创建一个新线程。如何在没有事件的情况下向具有该线程的频道发送消息。

【问题讨论】:

    标签: python multithreading discord discord.py python-multithreading


    【解决方案1】:

    您可以使用asyncio.get_event_loop().create_task(channel.send("example message"))。像这样使用它:

    import asyncio
    
    client = discord.Client()
    
    def funct():
        channel = client.get_channel(channel_id)
        asyncio.get_event_loop().create_task(channel.send("example message"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      • 2021-10-02
      • 2021-07-08
      • 2020-10-01
      • 2021-10-15
      • 2021-02-28
      • 2021-02-24
      相关资源
      最近更新 更多