尝试执行“检索所有聊天成员(也包括频道)”,但错误始终存在

时间:2018-06-26 02:01:21

标签: members telethon

我的代码有什么问题?我找到了包telethon,并且已经通过pip3安装了它。我认为第一步是让客户工作。我已经为此生成了电报API,因此我知道要替换xxxx,至于通道名称,我应该写通道名称吗?

我想念什么?

其中大部分是从Wiki复制粘贴的,所以我不确定错误在哪里

from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch
from time import sleep
from telethon import TelegramClient
from telethon.tl.functions.channels import GetFullChannelRequest


api_id = xxxxxxx
api_hash = 'xxxxxxxxxxxxxxxxx'
phone_number = 'xxxxxxxx'
################################################
channel_username = 'xxxxxxxxxx'
################################################

client = TelegramClient('session_name',api_id,api_hash)

assert client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone_number)
    me = client.sign_in(phone_number, input('Enter code: '))



offset = 0
limit = 100
all_participants = []
channel = client(GetFullChannelRequest(channel_username))

while True:
    participants = client.invoke(GetParticipantsRequest(
        channel, ChannelParticipantsSearch(''), offset, limit, hash=0
    ))
    if not participants.users:
        break
    all_participants.extend(participants.users)
    offset += len(participants.users)
    # sleep(1)  # This line seems to be optional, no guarantees!

0 个答案:

没有答案