Всем привет! Получаю список пользователей таким образом:
async def chat_members(chat_id: int) -> list[dict]:
"""Получает список участников чата."""
user_data: list[dict] = []
app = Client(
'Имя_Бот',
api_id=api_id,
api_hash=api_hash,
bot_token=bot_token,
in_memory=True,
)
await app.start()
async for member in app.get_chat_members(chat_id):
if not member.user.is_bot: # если пользователь не бот
user_data.append(
{
'user_id': member.user.id,
'first_name': member.user.first_name,
'last_name': member.user.last_name,
'user_name': member.user.username,
'is_admin_or_creator': await is_admin_or_creator(member),
}
)
await app.stop()
return user_data
Когда начинал писать бота создал чат для тестирования и в нем все нормально работает. Потом создал новый чат, назначил в нем бота админом и получаю ошибку
raise ValueError(f"Peer id invalid: {peer_id}")
ValueError: Peer id invalid: -1002220962355
Попробовал создать другой чат, та же ошибка, как ее пофиксить?
Весь лог ошибки:
"28.06.2024 12:26:44 - aiogram.event - [ERROR] - Cause exception while process update id=375533437 by bot id=6056035731
ValueError: Peer id invalid: -1002220962355"
Traceback (most recent call last):
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 62, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyrogram\storage\sqlite_storage.py", line 142, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: 'ID not found: -1002220962355'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 309, in _process_update
response = await self.feed_update(bot, update, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 158, in feed_update
response = await self.update.wrap_outer_middleware(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\middlewares\error.py", line 25, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\middlewares\user_context.py", line 49, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\fsm\middleware.py", line 42, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\event\telegram.py", line 121, in trigger
return await wrapped_inner(event, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\Python code\develop\telegram_bot\app\middlewares\middleware.py", line 20, in __call__
return await handler(event, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\event\handler.py", line 43, in call
return await wrapped()
^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 276, in _listen_update
return await self.propagate_event(update_type=update_type, event=event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\router.py", line 142, in propagate_event
return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\router.py", line 137, in _wrapped
return await self._propagate_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\router.py", line 170, in _propagate_event
response = await router.propagate_event(update_type=update_type, event=event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\router.py", line 142, in propagate_event
return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\router.py", line 137, in _wrapped
return await self._propagate_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\router.py", line 162, in _propagate_event
response = await observer.trigger(event, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\event\telegram.py", line 121, in trigger
return await wrapped_inner(event, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\dispatcher\event\handler.py", line 43, in call
return await wrapped()
^^^^^^^^^^^^^^^
File "F:\Python code\develop\telegram_bot\app\handlers\base_handlers.py", line 15, in start
user_data: list[dict] = await chat_members(chat.id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\Python code\develop\telegram_bot\app\services\services.py", line 36, in chat_members
async for member in app.get_chat_members(chat_id):
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyrogram\methods\chats\get_chat_members.py", line 115, in get_chat_members
peer = await self.resolve_peer(chat_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 89, in resolve_peer
peer_type = utils.get_peer_type(peer_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Anton\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyrogram\utils.py", line 246, in get_peer_type
raise ValueError(f"Peer id invalid: {peer_id}")
ValueError: Peer id invalid: -1002220962355