user16788304
user16788304

Reputation:

Python Telethon get all admins of group

I want to get admins of Telegram groups, I try with this code but I get empty response, my code

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

this is my response I've got

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

Upvotes: 2

Views: 5216

Answers (2)

zargham
zargham

Reputation: 1

I know your question is for long time ago, but still maybe someone had same question. Answer: your code is correct and return all admins of channel. and it have only 1 admin (showen by 'count=1' in your result). but you set 'offset' parameter to 42, but it has only 1 admin. so it show empty result. if your channel had let say 50 admins (indexing 0-49), by setting 'offset' to 42 it shows you from index 42 to 49.

Upvotes: 0

Lonami
Lonami

Reputation: 7141

As per the client reference, you can use client.iter_participants to iterate over the participants of a group. Furthermore, you can use the filter parameter to narrow down the results. The documentation also includes this example:

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

Upvotes: 4

Related Questions