skip to Main Content

Im using Pyrogram and Telegram Client API and i want to write program that will send messages to chats by using Pyrogram send_message() function. How can i get a unique identifier (int) of the target chat?

I tried to use peer id from browser developer console (f12), but when i put it inside the script it gives error: ValueError: Peer id invalid.

2

Answers


  1. Chosen as BEST ANSWER

    I asked ChatGPT to solve my problem and it worked:

    def get_ids():  
    with app:
        dialogs = app.get_dialogs()
        # Loop through all the dialogs (chats)
        for dialog in dialogs:
            chat = dialog.chat
            print(f"Chat ID: {chat.id}, Title: {chat.title or chat.first_name or chat.username}")
    

  2. From the Docs, send_message returns a Message object, you can get the group id by the .media_group_id parameter.

    message = ...
    group_id = message.media_group_id or None
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search