Pycord:复制频道消息并在线程中重新发送

问题描述 投票:0回答:1

好吧,我会解释一下我在这里做什么: 我希望我的机器人能够读取特定的频道,并且在该频道中发送的任何消息(无论什么,谁,图片,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 并且它可以工作,但不发送消息,所以问题是:

  1. client.get_channel 不适用于线程
  2. 机器人未在第二个频道中发送已读消息。

这只是代码的一部分,机器人的导入和启动已准备就绪。

我需要我的机器人读取频道并从该频道发送威胁消息。

python-3.x discord discord.py bots pycord
1个回答
0
投票

为什么你没有收到线程

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)

文档:

注意:我还没有测试过我之前编写的代码,但我相信它应该可以工作

© www.soinside.com 2019 - 2024. All rights reserved.