from pyrogram import Client from pyrogram.errors import PeerFlood import time vubor = input('Нажмите Enter чтобы запустить рассылку! ') api_id = 12905662 api_hash = "a7cfcd44cb95d26d7529d547c9a1d9ef" app = Client('my_accont11', api_id, api_hash) if vubor == '': def rassulka(app): try: with open('username.txt', 'r') as file: for users in file.readlines(): y = users.strip() time.sleep(5) app.send_message(y, 'q') file.replace(y, '') except PeerFlood: print('Аккаунт заблокировн') with app: rassulka(app) 

pyrogram.errors.exceptions.bad_request_400.PeerIdInvalid: 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

I do not know what to do

1

2 Answers

This error could mean several things (possible solution at the end):

  1. The chat id you tried to use is simply wrong, check it again.
  2. The chat id refers to a group or channel you are not a member of.
  3. The chat id argument you passed is in form of a string; you have to convert it into an integer with int(chat_id).
  4. The chat id refers to a user or chat your current session hasn’t met yet.

About the last point: in order for you to meet a user and thus communicate with them, you should ask yourself how to contact people using official apps. The answer is the same for Pyrogram too and involves normal usages such as searching for usernames, meeting them in a common group, having their phone contacts saved, getting a message mentioning them or obtaining the dialogs list.


possible solution

it might happen because you have passed only numerical IDs, as a string. Pyrogram tries to resolve those as a username, if it can't find those, it tries them as a phone number. If that still doesn't match, you get an error.

Try to use the method with an integer, as the IDs you tried, are integers.

app.get_chat(-12905662) { "_": "pyrogram.Chat", "id": -100123456789, } 

For write this code I used Pyrogram==1.3.6

from pyrogram import Client from pyrogram.types import Message from pyrogram.errors import PeerFlood import time vubor = input('Нажмите Enter чтобы запустить рассылку! ') app = Client( "my_accont11", api_id = 12219599, api_hash = "a7cfcd44cb95d26d7529d547c9a1d9ef") @app.on_message() async def main(Client,Message): if vubor == '': try: with open('username.txt', 'r') as file: for users in file.readlines(): y = users.strip() time.sleep(5) await app.send_message(chat_id=Message.from_user.id,y) new_file = file.read() new_file.replace(y, '') break except PeerFlood: print('Аккаунт заблокировн') app.run() 

For install Pyrogram 1.3.6:

pip install Pyrogram==1.3.6 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.