Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invite user by username to telegram channel

i trying to add users by usernames to my channel. I am using python 3.6 telethon library and pythonanywhere server:

api_hash = 'b7**'
phone = '+7***'
client = TelegramClient('new_ses', api_id, api_hash)
client.connect()
client = TelegramClient('session_neworig', api_id, api_hash,)
client.connect()

from telethon.tl.functions.channels import InviteToChannelRequest
from telethon.tl.functions.contacts import ResolveUsernameRequest
from telethon.tl.types import InputPeerChannel ,InputPeerUser,InputUser
from telethon.tl.functions.channels import JoinChannelRequest

chann=client.get_entity('channelname') #its public channel
print(chann.id)
1161823752

print(chann.access_hash)
8062085565372622341

time.sleep(30)
chan=InputPeerChannel(chann.id, chann.access_hash)
user = client(ResolveUsernameRequest('Chai***'))


print(user.users[0].id)
193568760
print(user.users[0].access_hash)
-4514649540347033311
time.sleep(1*30)

user=InputUser(user.users[0].id,user.users[0].access_hash,)

client.invoke(InviteToChannelRequest(chan,[user]))

This dosent work and i get -telethon.errors.rpc_error_list.PeerFloodError: (PeerFloodError(...), 'Too many requests')

what am i doing wrong? how to avoid it ? this one code is worked for me , but i am gone to flood after added let's say 20 users :

 from telethon.helpers import get_input_peer

client.invoke(InviteToChannelRequest(
    get_input_peer(client.get_entity(chan),
    [get_input_peer(client.get_entity(user))]
))

Please help , how to add 200 users by username without any ban , maybe there is another way to do it by python ? another lib or by api ?

like image 543
egorkh Avatar asked Jan 01 '18 15:01

egorkh


People also ask

How can I join a Telegram group with username?

Anybody can join your group through the link https://t.me/username . Your group appears in the Telegram search under @username.

What is the way to add bulk members to a Telegram group?

Manually Adding Telegram members You just have to have the phone contact of the person on your phone. Then open Channel info > Add Members > Select contacts. After confirming your actions, these people will be subscribed to your channel. Sure some of them may leave right away or with time.


1 Answers

Found somethin on Telegram API documentation website

Each phone number is limited to only a certain amount of logins per day (e.g. 5, but this is subject to change) after which the API will return a FLOOD error until the next day. This might not be enough for testing the implementation of User Authorization flows in client applications.

Link to source

like image 179
Alexander Ka Avatar answered Sep 22 '22 19:09

Alexander Ka