如何解决Telegram API Bot 邀请其他频道的订阅者加入我自己的频道
我想邀请其他电报频道的成员加入我的频道,但收到此错误 错误是:
raise ConnectionError('Connection to Telegram Failed {} time(s)'.format(self._retries))
ConnectionError: Connection to Telegram Failed 5 time(s)
我不知道为什么我会收到这个错误,我已经用代理检查过它,但它还是一样。 如果你们中有人知道这种类型的错误,请告诉我。我不知道这个。我知道这件事。这基本上是一个电报 api 机器人,我希望完全没有错误地完成。
import configparser
import json
import asyncio
import sys
import socks
from telethon import TelegramClient
from telethon.tl.types import InputPhoneContact
from telethon.tl.functions.contacts import ImportContactsRequest
from telethon.errors import FloodWaitError,RPCError
#import proxy
from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch
from telethon.tl.types import (
PeerChannel
)
# Reading Configs
config = configparser.ConfigParser()
config.read("config.ini")
# Setting configuration values
api_id = 1234567
api_hash = 'abcdefghjklmnopqrstuvwxyz1234567'
phone = '+123456789000'
username = '@abcdef'
#proxy='180.179.98.22:3128'
# Create the client and connect
client = TelegramClient(username,api_id,api_hash,proxy=(socks.soCKS5,'166.62.80.198',18726))
async def main(phone):
await client.start()
print("Client Created")
# Ensure you're authorized
if await client.is_user_authorized() == False:
await client.send_code_request(phone)
try:
await client.sign_in(phone,input('Enter the code: '))
except SessionPasswordNeededError:
await client.sign_in(password=input('Password: '))
me = await client.get_me()
user_input_channel = input("enter entity(telegram URL or entity id):")
if user_input_channel.isdigit():
entity = PeerChannel(int(user_input_channel))
else:
entity = user_input_channel
my_channel = await client.get_entity(entity)
offset = 0
limit = 100
all_participants = []
while True:
participants = await client(GetParticipantsRequest(
my_channel,ChannelParticipantsSearch(''),offset,limit,hash=0
))
if not participants.users:
break
all_participants.extend(participants.users)
offset += len(participants.users)
all_user_details = []
for participant in all_participants:
all_user_details.append(
{"id": participant.id,"first_name": participant.first_name,"last_name": participant.last_name,"user": participant.username,"phone": participant.phone,"is_bot": participant.bot})
with open('user_data.json','w') as outfile:
json.dump(all_user_details,outfile)
with client:
client.loop.run_until_complete(main(phone))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。