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, @aahnik! how do I make it so that the cat can access channels via private links?
Hi!
Do you solve this problem?
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.