skip to Main Content

I am trying to get users from a group using a telegram bot . I am using python’s telethon library for this purpose . Here is the code and the full error message –

from telethon import TelegramClient, events
API_ID = 123
API_HASH = '##'  
BOT_TOKEN  ="##" 
bot = TelegramClient('bot', API_ID, API_HASH)
bot.start(bot_token=BOT_TOKEN) 
async def Get_Random():
    users = await bot.get_participants(-123)
    print(users[0].first_name)
    for user in users:
        if user.username is not None:
            print(user.username)
bot.loop.run_until_complete(Get_Random())

Full error –

telethon.errors.rpcerrorlist.PeerIdInvalidError: An invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations) (caused by GetFullChatRequest)

Bot is already an admin of the group .

2

Answers


  1. Chosen as BEST ANSWER

    For anyone who is stuck and viewing this , You need to be part of the telegram group for which you are fetching the data . Joining that telegram group resolved my error .


  2. The error is explanatory itself. The ID of a peer you passed to the method is invalid.

    You should reassure that the chat ID you passed is correct.

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