简体   繁体   English

如何在 discord.py 中发送没有@client.event 的消息?

[英]How to send message without @client.event in discord.py?

I need a way to constantly check for the message 'kill' in discord.py. I have many while loops in my code so I need to create a new thread with the threading module.我需要一种方法来不断检查 discord.py 中的消息'kill' 。我的代码中有很多 while 循环,所以我需要使用线程模块创建一个新线程。 How can I send a message to a channel with that thread without the events.如何在没有事件的情况下将消息发送到具有该线程的通道。

You can use asyncio.get_event_loop().create_task(channel.send("example message")) .您可以使用asyncio.get_event_loop().create_task(channel.send("example message")) Use it like this:像这样使用它:

import asyncio

client = discord.Client()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM