【发布时间】:2022-02-22 16:56:33
【问题描述】:
我想使用 Telethon 来Retrieving all chat members。
这是我的代码:
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch
from time import sleep
api_id = 134565
api_hash = 'xxxxxx'
client = TelegramClient(None, api_id, api_hash)
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
client.sign_in(phone, input('Enter the code: '))
offset = 0
limit = 100
all_participants = []
while True:
participants = client(GetParticipantsRequest(
channel, ChannelParticipantsSearch(''), offset, limit,
hash=0
))
if not participants.users:
break
all_participants.extend(participants.users)
offset += len(participants.users)
Note
代码出现以下错误: 我试试这个Q/A,但它没有关于错误的足够信息。
<module>
19 hash=0
20 ))
---> 21 if not participants.users:
22 break
23 all_participants.extend(participants.users)
AttributeError: 'coroutine' object has no attribute 'users'
如何解决这个问题?
【问题讨论】:
-
您需要提供更详细的错误信息
-
首先,您应该提供可重现的代码,例如您缺少从 Telethon 导入 TelegramClient。与我想你想做的相关,是检索聊天中的参与者,你可以使用这种方法来代替,get_participants。