【发布时间】: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