Search code examples
pythontelegramtelegram-bottelethon

how to join multiple telegram group with telethon


I want to join multiple groups with telethon python but I can't I can only able to join one group at a time anyone knows how to join multiple groups at the same time

with TelegramClient(name, api_id, api_hash) as client:
    result = client(functions.channels.JoinChannelRequest(
        channel='username'
    ))

Solution

  • You can use a for loop in order to loop and join the groups one by one. Your code can be as such:

    groups = ['group_1', 'group_2']
    with TelegramClient(name, api_id, api_hash) as client:
        for group in groups:
            result = client(functions.channels.JoinChannelRequest(
                channel=group
            ))
            time.sleep(60) # or await asyncio.sleep(60)
    

    Make sure to have some sort of a delay too or you'll get your account suspended or banned.