i write a simple code with pyrogram to get messages from a public channel.
i get the chaanel_id and passed it to the function but teh code raise an error.
could you please help me why it raises this error although the channel_id is correct?
this is my code:
app = Client("my_botn", api_id=int(api_id), api_hash=api_hash,proxy=proxy)
async def get_chat_history(chat_id):
async with app:
async for message in app.get_chat_history(-1002245761378):
print(message.text)
chat_id=-1002245761378
app.run(get_chat_history(chat_id))
error is :
Tr
aceback (most recent call last):
File "C:UsersMohammadvenvLibsite-packagespyrogrammethodsadvancedresolve_peer.py", line 62, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersMohammadvenvLibsite-packagespyrogramstoragesqlite_storage.py", line 142, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: 'ID not found: -1002245761378'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:UsersMohammadvenvmybot.py", line 19, in <module>
app.run(get_chat_history(chat_id))
File "C:UsersMohammadvenvLibsite-packagespyrogrammethodsutilitiesrun.py", line 77, in run
run(coroutine)
File "C:UsersMohammadAppDataLocalProgramsPythonPython312Libasynciobase_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
File "c:UsersMohammadvenvmybot.py", line 16, in get_chat_history
File "c:UsersMohammadvenvmybot.py", line 16, in get_chat_history
async for message in app.get_chat_history(int(-1002245761378)):
File "C:UsersMohammadvenvLibsite-packagespyrogrammethodsmessagesget_chat_history.py", line 101, in get_chat_history
File "C:UsersMohammadvenvLibsite-packagespyrogrammethodsmessagesget_chat_history.py", line 101, in get_chat_history
messages = await get_chunk(
messages = await get_chunk(
^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^
File "C:UsersMohammadvenvLibsite-packagespyrogrammethodsmessagesget_chat_history.py", line 37, in get_chunk
File "C:UsersMohammadvenvLibsite-packagespyrogrammethodsmessagesget_chat_history.py", line 37, in get_chunk
peer=await client.resolve_peer(chat_id),
peer=await client.resolve_peer(chat_id),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersMohammadvenvLibsite-packagespyrogrammethodsadvancedresolve_peer.py", line 89, in resolve_peer
peer_type = utils.get_peer_type(peer_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersMohammadvenvLibsite-packagespyrogramutils.py", line 246, in get_peer_type
raise ValueError(f"Peer id invalid: {peer_id}")
ValueError: Peer id invalid: -1002245761378
New contributor