簡體   English   中英

通過用戶名邀請用戶到電報頻道

[英]invite user by username to telegram channel

我試圖通過用戶名將用戶添加到我的頻道。 我正在使用 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') ,我得到了-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 ?

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')

在 Telegram API 文檔網站上找到了一些東西

每個電話號碼每天只能進行一定數量的登錄(例如 5 次,但這可能會發生變化),之后 API 將在第二天返回 FLOOD 錯誤。 這可能不足以測試客戶端應用程序中用戶授權流的實現。

鏈接到源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM