【问题标题】:invite user by username to telegram channel通过用户名邀请用户到电报频道
【发布时间】:2018-06-11 13:48:41
【问题描述】:

我试图通过用户名将用户添加到我的频道。我正在使用 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 ?

【问题讨论】:

  • 不要在 Telegram 中发送垃圾邮件
  • @Sean 我试图从我的频道添加用户聊天,我不认为你可以称之为垃圾邮件。及其仅有的 200 个用户
  • 你为什么不给他们加入链接?
  • 因为我正在探索 Telethon lib 并坚持使用这种方法
  • 你找到答案了吗?

标签: python python-3.x web telegram telethon


【解决方案1】:

在 Telegram API 文档网站上发现了一些东西

每个电话号码每天只能进行一定的登录次数(例如 5 次,但可能会有所变化),之后 API 将返回 FLOOD 错误,直到第二天。这可能不足以测试客户端应用程序中用户授权流程的实现。

Link to source

【讨论】:

    【解决方案2】:
    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')
    

    【讨论】:

      猜你喜欢
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 2018-08-06
      • 1970-01-01
      相关资源
      最近更新 更多