Here is an example of .env
file you need to use:
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()) |
hi, @MaksGruv52, I have updated the code in the gist. Please try again.
Put a few invalid channels, and some valid channels, on encountering an error, it will not stop. It will print the error on the terminal, and continue with the next channel.
star this gist, so that it reaches more people!
Hi, thank you very much! I'll start testing it now!
How to add a group interval? You will soon be prompted "waiting for a wait of * * * * seconds is required"
hy man! im trying to run your code, but i always got an error message:
The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by JoinChannelRequest)
Encountered an error while joining @cryptolinksgroup
at point it asked my phone, or bot token. my phone have a token access? i thought only api id, and hash have.
hi, @aahnik! how do I make it so that the cat can access channels via private links?
Hi!
Do you solve this problem?
please tell me how to add the function of skipping the channel error (if it does not exist or the channel is banned) and the script continued to add it?