首页 > 解决方案 > Python Telethon 获取组的所有管理员

问题描述

我想获得电报组的管理员,我尝试使用此代码,但我得到空响应,我的代码

client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    client.sign_in(phone, input('Enter the code: '))
result = client(functions.channels.GetParticipantsRequest(
    channel='mychannel',
    filter=types.ChannelParticipantsAdmins(),
    offset=42,
    limit=100,
    hash=0
))
print(result.stringify())

这是我的回应

ChannelParticipants(
        count=1,
        participants=[
        ],
        users=[
        ]
)

标签: pythontelegramtelethon

解决方案


根据客户端参考,您可以使用client.iter_participants迭代组的参与者。此外,您可以使用该filter参数来缩小结果范围。该文档还包括此示例:

# Filter by admins
from telethon.tl.types import ChannelParticipantsAdmins
async for user in client.iter_participants(chat, filter=ChannelParticipantsAdmins):
    print(user.first_name)

推荐阅读