How to add members to Telegram with pyrogram?

1.3k Views Asked by At

I have been able to login to Telegram and send messages to myself and also retrieve users from a group. But whenever I try to add members to a group, I get an error.

Here is my code

from pyrogram import Client
import asyncio
from pyrogram.errors import FloodWait

TARGET = 'intendingcouples_class'

async def main():
    app = Client("my_account")

users = []

async with app:
    async for member in app.get_chat_members(TARGET):
        users.append(member.user.id)
    print(users)
    await app.add_chat_members('myenki', member.user.id)
    
asyncio.run(main())

When I run the above code, I get this error

pyrogram.errors.exceptions.flood_420.FloodWait: Telegram says: [420 FLOOD_WAIT_X] - A wait of 73958 seconds is required (caused by "channels.InviteToChannel")

Please, how do I solve this problem?

1

There are 1 best solutions below

0
On BEST ANSWER

Your error is clear:
pyrogram.errors.exceptions.flood_420.FloodWait: Telegram says: [420 FLOOD_WAIT_X] - A wait of 73958 seconds is required (caused by "channels.InviteToChannel")

You'll have to wait 73958 seconds to be able to use the method again. Besides that, adding members against their will to random groups can get both your group, and your account permanently banned.