6

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 ?

egorkh
  • 478
  • 8
  • 24

2 Answers2

1

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Alexander Ka
  • 259
  • 1
  • 2
  • 11
0
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import InviteToChannelRequest
from telethon.tl.types import InputPeerChannel ,InputUser
from telethon.tl.functions.contacts import ResolveUsernameRequest

api_id = ******
api_hash = '******'
phone = '+2519******'
client = TelegramClient(phone, api_id, api_hash);
client.connect()


chann=client.get_entity('channelname') 
channel_id = chann.id;
channel_access_hash = chann.access_hash

chanal=InputPeerChannel(channel_id, channel_access_hash)
user = client(ResolveUsernameRequest('mrmi6'))

user=InputUser(user.users[0].id,user.users[0].access_hash,)
client(InviteToChannelRequest(chanal,[user]))
print('action completted')
Girma
  • 23
  • 1
  • 5