【问题标题】:Check who sends message检查谁发送消息
【发布时间】:2020-07-06 19:50:16
【问题描述】:

我非常不擅长 python(和编程)。我正在尝试创建简单的“转发客户端”。

我希望我的电报客户端将消息转发到saved messages,所以我这样做了:

api_id = ****
api_hash = '****'

with TelegramClient('name', api_id, api_hash) as client:
   @client.on(events.NewMessage(outgoing='true', incoming='true'))
   async def handler(event):
      await event.message.forward_to('me')
   client.run_until_disconnected()

一切正常,但我只想转发我的消息和来自用户的消息。不是来自群组或公共频道。

我该怎么做?在文档中找不到任何内容

谢谢

【问题讨论】:

    标签: python telegram telethon


    【解决方案1】:

    您非常接近,只需在events.NewMessage 上添加chats 参数。阅读文档here 了解更多信息

    这是你想要的代码:

    api_id = ****
    api_hash = '****'
    
    with TelegramClient('name', api_id, api_hash) as client:
       @client.on(events.NewMessage(outgoing='true', incoming='true', chats=[xxxxx, xxxx]))
       async def handler(event):
          await event.message.forward_to('me')
       client.run_until_disconnected()
    

    chats 参数需要一个实体列表(阅读有关实体here 的更多信息)

    如果您正在寻找一个简单的解决方案,您可以随时使用我制作的这个电报机器人@tg_feedbot

    这是一个用于将消息从一个/多个组转发给其他组的机器人。它的工作方式是使用您的电报帐户,当一条消息来临时 - 如果您已配置它 - 它会看到它并将其重写到您想要的频道。您可以编辑消息的外观、过滤、延迟和更改字词。

    它是自动化Telegram User API 的免费解决方案,它与documentation 一起具有简单易用的界面

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多