我试图通过用户名将用户添加到我的频道。我正在使用 python 3.6 telethon 库和 pythonanywhere 服务器:
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]))
这剂量有效,我得到-telethon.errors.rpc_error_list.PeerFloodError: (PeerFloodError(...), 'Too many requests')
我究竟做错了什么?如何避免呢?这个代码对我有用,但是添加后我就被淹没了,比如说 20 个用户:
from telethon.helpers import get_input_peer
client.invoke(InviteToChannelRequest(
get_input_peer(client.get_entity(chan),
[get_input_peer(client.get_entity(user))]
))
请帮忙,如何通过用户名添加200个用户而没有任何禁令,也许还有另一种方法可以通过python做到这一点?另一个库或通过 api ?