Getting participants of a group/channel
GramJS provides two friendly methods to get a list of participants from a channel a group.
The interface looks like this. you can read more about filters here https://core.telegram.org/type/ChannelParticipantsFilter
export interface IterParticipantsParams {
limit?: number,
search?: string,
filter?: Api.TypeChannelParticipantsFilter,
}
getParticipants(entity: EntityLike, params: chatMethods.IterParticipantsParams);
which returns an array with a .total
attribute returning the real number of users in the group.
you can also use an iterator with iterParticipants
Examples:
Using iterParticipants
iterParticipants
const participants = client.iterParticipants("your_entity_here", {
limit: 10,
});
for await (const participant of participants) {
//console.log("participant is", participant); // this line is very verbose but helpful for debugging
console.log("username text is : ", participant.username);
}
Using getParticipants
getParticipants
const result = await client.getParticipants("gramjs",{
limit:10
});
console.log(result);
Last updated
Was this helpful?