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

编程入门 行业动态 更新时间:2024-10-28 07:34:36
本文介绍了在电报组中关注用户的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

每当用户在大型电报组中发布新消息时,我都需要得到通知.最好的方法是什么?有没有现成的机器人或方法?例如,我可以创建一个新频道,其帖子是该用户的帖子吗?

I need to get notified whenever a user posts a new message in a large telegram group. What is the best way to do that? Is there any ready bot or method for this? for example can I make a new channel which its posts are posts of that user?

推荐答案

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

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.

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

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

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

这篇关于在电报组中关注用户的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 07:07:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405836.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电报   组中   消息   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!