skip to Main Content

I wrote a simple script on python to copy messages in one chat to the other. The destination chat is a chat with a telegram bot.
It works perfectly on my computer, but I wanted it to work on my Raspberry Pi (not to keep my Windows computer ON). When I started the script on Raspberry it started to place the error:

Telegram says: [400 PEER_ID_INVALID] – The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/pyrogram/methods/advanced/resolve_peer.py", line 60, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
File "/usr/local/lib/python3.7/dist-packages/pyrogram/storage/sqlite_storage.py", line 148, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: ‘ID not found: 1321800342’

So I checked all didgets, everything is right, checked the chat id again. I have an idia, that the problem is that exactly that device (Raspberry Pi) didn’t write to that bot itself. But maybe I am wrong.
Did anyone has the same issue? Do you have any idias how to solve it?
Thanks a lot.

 from pyrogram import Client, filters

# Target chat. Can also be a list of multiple chat ids/usernames
TARGET = -730374088

app = Client("my_account")


# Filter in only new_chat_members updates generated in TARGET chat
@app.on_message(filters.chat(TARGET) & filters.text)
async def welcome(client, message):
    await app.send_message(1321800342, message.text)


app.run()  # Automatically start() and idle()

2

Answers


  1. Chosen as BEST ANSWER

    Worked well when I changed chat id to the bot's username.


  2. The new session on your Pi likely hasn’t seen the chat/channel, and thus doesn’t know what to associate the ID to. Make sure the new session receives any kind of update from the chat/channel and read Pyrogram’s FAQ section on the error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search