且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在电报组中关注用户的消息

更新时间:2023-10-22 22:55:58

你要做的是收听来自该聊天(组)的传入消息更新 -> 仅过滤用户发送的消息 -> 转发该消息到特定频道.

What you've to do is to listen to incoming message updates from that chat(group) -> Filter only these sent by the user -> forward that message to a specific channel.

这是 telethon 中的工作示例代码:

Here is a working sample code in telethon:

from telethon import TelegramClient, events

API_ID = ...
API_HASH = " ... "

BOT_TOKEN = " ... "

client = TelegramClient('session', api_id=API_ID, api_hash=API_HASH).start(bot_token=BOT_TOKEN)

@client.on(events.NewMessage(
    chats=" ... ",  # insert group username here
    from_users=" ..."  # insert a user to monitor here
))
async def _(event):
    await event.message.forward_to(" ... ") # insert the username for the receiver chat/channel

with client:
    client.run_until_disconnected()

您可以从 https 中找到 API_IDAPI_HASH 值://my.telegram.org.

You can find the API_ID and API_HASH values from https://my.telegram.org.

另外在这里阅读 Telethon 的文档,如果您想添加/修改行为.

Also read telethon's Documentation here if you wish to add/modify the behavior.