I’m trying to join a lot of telegram groups on one account. I’ve made a script in python that uses telethon to do the job but it fails miserably and gets rate limited extremely fast.
Ignore the “time.sleep(2)” being set at 2 seconds, I normally run it at 5 minutes each
from opentele.tl import TelegramClient
from opentele.api import API
from telethon.errors import FloodWaitError
from telethon.tl.functions.messages import ImportChatInviteRequest
import time
import asyncio
# Replace these with your own session name and phone number
session_name = 'your_session_name' # e.g., 'account1'
phone_number = 'PHONE NUMBER' # Your phone number, including country code
# Load group invite links from a file
with open('groups.txt', 'r') as file:
group_invite_links = [line.strip() for line in file if line.strip()]
async def join_groups():
api = API.TelegramDesktop # Use Telegram Desktop's official API
client = TelegramClient(session_name, api=api)
# Start the client and log in
await client.start(phone=phone_number)
for invite_link in group_invite_links:
try:
# Extract the invite hash from the invite link
if 'joinchat' in invite_link:
invite_hash = invite_link.split('/')[-1]
else:
# Handle t.me/+inviteHash format
invite_hash = invite_link.split('/')[-1].lstrip('+')
await client(ImportChatInviteRequest(invite_hash))
print(f"Joined group: {invite_link}")
# Add a delay to avoid triggering flood wait
time.sleep(2) # Adjust the delay as needed
except FloodWaitError as e:
print(f"Flood wait for {e.seconds} seconds")
time.sleep(e.seconds) # Wait out the flood wait time
except Exception as e:
print(f"Error joining group {invite_link}: {e}")
await client.disconnect()
# Run the async function
asyncio.run(join_groups())
I tried prolonging the sleep time, it does work but it would take me a month to join all the groups I wish to join with a higher sleep time, it would already take approximately 17 days with the script provided above.
2