如果源消息被删除,如何删除目标电报消息

2024-06-09 16:38:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Telethon创建一个python程序,以找到在源消息被删除后删除目标通道中消息的方法

例如:
A--源频道
B——目的地信道

A发布一条消息X,该消息被转发到目标通道B。一段时间后,A删除消息X,B也应该删除该消息

我的代码如下所示:

@client.on(events.MessageDeleted)
async def edit_message_bot(event):
    ...

但问题是,当我使用此方法时,事件中的msg_id对于源通道和目标通道是不同的,因此无法找到删除它的方法

请帮忙


Tags: 方法代码程序client消息目标asyncon
1条回答
网友
1楼 · 发布于 2024-06-09 16:38:44

我为MessageDeleted事件找到了source code,文档显示:

Telegram does not send information about where a message was deleted if it occurs in private conversations with other users or in small group chats, because message IDs are unique and you can identify the chat with the message ID alone if you saved it previously.

Telethon does not save information of where messages occur, so it cannot know in which chat a message was deleted (this will only work in channels, where the channel ID is present).

This means that the chats= parameter will not work reliably, unless you intend on working with channels and super-groups only.

在您的例子中,您应该获得chats参数,这会有所帮助。另外,您应该使用deleted_ids,而不是msg_idLink

我认为您应该将原始消息的消息id和消息的id存储在目标频道中,以便轻松找到它。因此,您将拥有类似于字典的东西,其中原始id和新id存储在一起

相关问题 更多 >