Skip to content

Instantly share code, notes, and snippets.

@zlk-pixel
Forked from aahnik/#channel joiner.md
Created October 28, 2021 12:42
Show Gist options
  • Save zlk-pixel/e7acd0c572c096624c1986e683524fcf to your computer and use it in GitHub Desktop.
Save zlk-pixel/e7acd0c572c096624c1986e683524fcf to your computer and use it in GitHub Desktop.
Telethon , telegram , join telegram channels from a list

Here is an example of .env file you need to use:

Screenshot from 2021-01-15 17-21-41

Make sure to have telethon and python-dotenv installed.

# make sure to have telethon and python-dotenv installed
# create a file called .env in the current directory from where you are running the script
# put API_ID and API_HASH in the .env file in the following format
# VARIABLE=VALUE
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import JoinChannelRequest
from telethon.errors.rpcerrorlist import FloodWaitError
from dotenv import load_dotenv
import os
import asyncio
load_dotenv()
API_ID = os.getenv('API_ID')
API_HASH = os.getenv('API_HASH')
CHANNELS = ['a', 'b', 'c'] # the channels you want to join
async def main():
async with TelegramClient('tg_session', API_ID, API_HASH) as client:
for channel in CHANNELS:
try:
await client(JoinChannelRequest(channel))
except FloodWaitError as fwe:
print(f'Waiting for {fwe}')
await asyncio.sleep(delay=fwe.seconds)
except Exception as err:
print(f"Encountered an error while joining {channel}\n{err}")
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment