如果我知道这些频道 ID,是否可以从我的帐户中加入 100 个电报频道? 由于电报 API 限制,机器人无法使用,这是否可以让我的用户自动化?我想输入电报 ID,我的帐户将加入这些频道并发送特定消息。我研究了一下,一无所获
答案 0 :(得分:1)
是的,这是可能的。
使用这个脚本
# 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)
asyncio.run(main())
以下是您需要使用的 .env
文件示例:
确保安装了 telethon
和 python-dotenv
。