【发布时间】:2022-10-07 23:05:03
【问题描述】:
我需要一种方法来不断检查 discord.py 中的消息 'kill'。我的代码中有很多 while 循环,所以我需要使用 threading 模块创建一个新线程。如何在没有事件的情况下向具有该线程的频道发送消息。
【问题讨论】:
标签: python multithreading discord discord.py python-multithreading
我需要一种方法来不断检查 discord.py 中的消息 'kill'。我的代码中有很多 while 循环,所以我需要使用 threading 模块创建一个新线程。如何在没有事件的情况下向具有该线程的频道发送消息。
【问题讨论】:
标签: python multithreading discord discord.py python-multithreading
您可以使用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"))
【讨论】: