Get all participants of a channel using WTelgramClient, only returning 200

1.5k Views Asked by At

I have a channel and i would like to remove some users. I have used code from WTelegramClient to get all the participants, but for some reason it is only returning 200? We have 31k members.

Here is the code i am using to get participants, which is the same as on the examples.

var deleted = new List<User>();
var bannedRights = new ChatBannedRights();
bannedRights.flags = 0;// ChatBannedRights.Flags.change_info | ChatBannedRights.Flags.embed_links | ChatBannedRights.Flags.invite_users | ChatBannedRights.Flags.pin_messages | ChatBannedRights.Flags.send_games | ChatBannedRights.Flags.send_gifs | ChatBannedRights.Flags.send_inline | ChatBannedRights.Flags.send_media | ChatBannedRights.Flags.send_messages | ChatBannedRights.Flags.send_polls | ChatBannedRights.Flags.send_stickers | ChatBannedRights.Flags.view_messages;

// now loop through our tweets
for (int offset = 0; ;)
{
    var participants = await client.Channels_GetParticipants(channel, null, offset, 100, accessHash);

    for (var i = 0; i < participants.users.Count; i++)
    {
        var participant = (ChannelParticipant)participants.participants[i];
        var member = (User)participants.users[participant.user_id];
        
        if (participant.date.Year == _joinedOn.Year && participant.date.Month == _joinedOn.Month && participant.date.Day == _joinedOn.Day)
        {
            Console.Write(string.Format("Removing user '{0}' as joined on {1}...", member.username, _joinedOn));
            await client.Channels_EditBanned(channel, member, bannedRights);

            deleted.Add(member);
        }
    }

    offset += participants.participants.Length;
    
    if (offset >= participants.count) break;
}

I am guesing there is a server restriction or something? Much help appreciated

1

There are 1 best solutions below

1
On BEST ANSWER

This is due to a Telegram server-side enforced limitation that restrict to only 200 members when querying the list of members on some (big) groups/channels.

There is now a new method in WTelegramClient that work-around this limit and tries to get all the participants in the channel:

var participants = await client.Channels_GetAllParticipants(channel);

It can take a few minutes to complete for big channels/groups and will likely not be able to obtain the full list of participants but it will go beyond that 200 or 10k member limit