【问题标题】:How to capture the channel messages in Telegram using Telethon?如何使用 Telethon 捕获 Telegram 中的频道消息?
【发布时间】:2018-01-10 16:41:46
【问题描述】:

我想捕获频道消息并将它们发送到另一个 python 函数。 通过使用文档,我可以连接到 Telegram 服务器并进行身份验证。但是,我不知道如何捕获频道消息。

文档提供了如下方法:

channels.getMessages#93d7b347 channel:InputChannel id:Vector<int> = messages.Messages

channel 是一个InputChannel。以下是文档

inputChannel#afeb712e channel_id:int access_hash:long = InputChannel

我无法理解如何获取 channel_id 和 access_hash。 我也不明白要为id:Vector&lt;int&gt;提供什么

如果我想捕获每条消息。我必须在无限循环中运行它吗? 一个小例子将不胜感激。

【问题讨论】:

  • @stovfl 我仍然不知道如何找到channel_idvector&lt;int&gt; 实体。我还认为 access_hash 指的是频道实体。在找出通道 id 和向量实体是什么之后,我将尝试使用电报 API 哈希来代替它。

标签: python python-3.x telegram telethon


【解决方案1】:

相关:join-a-channel


问题:不知道如何找到channel_id

from telethon.utils import get_display_name

# Retrieve the top 10 dialogs
# Entities represent the user, chat or channel
# corresponding to the dialog on the same index
dialogs, entities = client.get_dialogs(10)
 
# Display them, 'i'
for i, entity in enumerate(entities, start=1):
     print('{}. {}'.format(i, get_display_name(entity)))

问题:我不明白为 id:Vector

提供什么

Core types
Vector:如果类型 T 包裹在 Vector 周围,则意味着参数应该是它的列表。
例如,Vector 的有效值为 [1, 2, 3]

【讨论】:

  • 除非我知道向量参数的含义,否则我不知道要传递给它什么。它肯定需要知道哪个频道 id,所以我传递了频道 id,但在这种情况下,向量参数意味着什么?谢谢你:)
猜你喜欢
  • 2022-07-17
  • 1970-01-01
  • 1970-01-01
  • 2018-05-02
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
  • 2021-04-11
  • 1970-01-01
相关资源
最近更新 更多