简体   繁体   English

如何使用 Telethon 将选定人员的消息从电报组 A 转发到电报组 B

[英]How to forward messages of selected people from telegram group A to telegram group B using telethon

So I'm able to send all the chats of specified group to another group with the help of telethon's telegramclient and events below is my code.所以我可以在 Telethon 的电报客户端的帮助下将指定组的所有聊天发送到另一个组,下面的事件是我的代码。

from telethon import TelegramClient, events
api_id = YOUR_ID
api_hash = YOUR_HASH
client = TelegramClient('anon', api_id, api_hash)

@client.on(events.NewMessage(chats=CHAT_ID_A))
async def handle_new_message(event):
    await client.send_message(CHAT_ID_B, event.raw_text)

Help me to refactor this code in such a way that I can send messages of only selected users from telegram group A to telegram group B帮助我重构此代码,以便我可以仅将选定用户的消息从电报组 A 发送到电报组 B

After a bit of searching adding the following inside event definition will to the trick经过一番搜索后,将以下内部事件定义添加到技巧中

    sender_chat_id = event.sender_id
    if sender_chat_id == SELECTED_ID:
        await client.send_message(CHAT_ID_B, event.raw_text)

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

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