好吧,我会解释一下我在这里做什么: 我希望我的机器人能够读取特定的频道,并且在该频道中发送的任何消息(无论什么,谁,图片,gif,嵌入)机器人都会在线程本身中发送它,所以我问了人工智能,我得到了这个:
itents.messages = True
@client.event
async def on_message(message):
if message.channel.id == 1166507853314539561:
thread = client.get_channel(1209617468188925993)
if message.content:
await thread.send(message.content)
for embed in message.embeds:
await thread.send(embed=embed)
使用此代码,机器人正在读取源通道,但他没有读取线程通道,我认为 client.get_channel 不适用于线程,我可以使用通道 ID 并且它可以工作,但不发送消息,所以问题是:
这只是代码的一部分,机器人的导入和启动已准备就绪。
我需要我的机器人读取频道并从该频道发送威胁消息。
client.get_channel
从缓存中获取,并且 only 获取通道。我们想要的是线程。
channel.get_thread(thread_id)
将会起作用。
@client.event
async def on_message(message):
if message.channel.id == 1166507853314539561:
channel = client.get_channel(channelID) # replace with channel ID of where the thread is
if channel is None:
client.fetch_channel(channelID) # fetch if not found in cache
thread = channel.get_thread(thread_id) # use the thread ID
if message.content:
await thread.send(message.content)
for embed in message.embeds:
await thread.send(embed=embed)
注意:我还没有测试过我之前编写的代码,但我相信它应该可以工作