@Meezmo

Почему не работает код telethon?

Хотел написать небольшой скрипт который будет собирать номера телефонов участников груп. Но когда хочу получить всех участников групы выдаёт ошибку. Вот код:
from telethon.sync import TelegramClient
from telethon import functions, types
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch
api_id = секрет
api_hash = "секрет"
client = TelegramClient("me", api_id, api_hash)
channel = "-684219951"
async def main():
    async for dialog in client.iter_dialogs():
        print(dialog.name, 'has ID', dialog.id)
participants = client(GetParticipantsRequest(channel, ChannelParticipantsSearch(''), 0, 11, 100))
with client:
    client.loop.run_until_complete(main())

Вот ошибка:
Traceback (most recent call last):
  File "D:/PYTHON/test library/teleton test.py", line 12, in <module>
    participants = client(GetParticipantsRequest(channel, ChannelParticipantsSearch(''), 0, 11, 100))
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\client\users.py", line 39, in _call
    await r.resolve(self, utils)
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\tl\functions\channels.py", line 904, in resolve
    self.channel = utils.get_input_channel(await client.get_input_entity(self.channel))
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\client\users.py", line 437, in get_input_entity
    await self._get_entity_from_string(peer))
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\client\users.py", line 529, in _get_entity_from_string
    for user in (await self(
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\client\users.py", line 63, in _call
    future = sender.send(request, ordered=ordered)
  File "D:\PYTHON\test library\venv\lib\site-packages\telethon\network\mtprotosender.py", line 172, in send
    raise ConnectionError('Cannot send requests while disconnected')
ConnectionError: Cannot send requests while disconnected

Заранее спасибо.
  • Вопрос задан
  • 65 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы