【问题标题】:ValueError: Cannot find any entity corresponding to "Test"ValueError:找不到与“测试”对应的任何实体
【发布时间】:2021-05-14 18:39:27
【问题描述】:

我正在努力学习 Telethon。我想从我创建的“测试”组中获取所有消息

import os
import sys
import time

from telethon import TelegramClient, events, utils,sync
from telethon.tl.types import Chat


api_id = **
api_hash = '**'
proxy = None 
phone_number='*****'

client = TelegramClient('session_name', api_id, api_hash)
client.start()
channel_username = 'Test' //<==Group Name
for message in client.get_messages(channel_username, limit=10):
    print(message.message)

但我总是得到这个错误


<module>
    for message in client.get_messages(channel_username, limit=10):
  File "C:\Python39\lib\site-packages\telethon\sync.py", line 39, in syncified     
    return loop.run_until_complete(coro)
  File "C:\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete   
    return future.result()
  File "C:\Python39\lib\site-packages\telethon\client\messages.py", line 574, in get_messages
    return await it.collect()
  File "C:\Python39\lib\site-packages\telethon\requestiter.py", line 113, in collect
    async for message in self:
  File "C:\Python39\lib\site-packages\telethon\requestiter.py", line 58, in __anext__
    if await self._init(**self.kwargs):
  File "C:\Python39\lib\site-packages\telethon\client\messages.py", line 26, in _init
    self.entity = await self.client.get_input_entity(entity)
  File "C:\Python39\lib\site-packages\telethon\client\users.py", line 432, in get_input_entity
    await self._get_entity_from_string(peer))
  File "C:\Python39\lib\site-packages\telethon\client\users.py", line 569, in _get_entity_from_string
    raise ValueError(
ValueError: Cannot find any entity corresponding to "Test"

谁能帮我解决这个问题

【问题讨论】:

  • channel_username 必须是频道用户名或频道 ID,而不是频道名称。
  • @PrashantSengar Ohk thnx

标签: python telegram telethon


【解决方案1】:

您应该输入一个实体(id 或 ....)来获取消息

例如:

channel_username = "@telegram"

【讨论】:

  • 我有组的ID如何获取实体?
猜你喜欢
  • 1970-01-01
  • 2021-11-23
  • 1970-01-01
  • 2021-11-21
  • 1970-01-01
  • 2019-10-16
  • 1970-01-01
  • 2019-06-14
  • 2015-07-22
相关资源
最近更新 更多