Chat.iter_members()

Chat.iter_members()

Bound method iter_members of Chat.

Use as a shortcut for:


Parameters
  • limit (int, optional) – Limits the number of members to be retrieved. Only applicable to supergroups and channels. Defaults to 200, which is also the maximum server limit allowed per method call 1.

  • query (str, optional) – Query string to filter members based on their display names and usernames. Only applicable to supergroups and channels. Defaults to “” (empty string) 2.

  • filter (str, optional) – Filter used to select the kind of members you want to retrieve. Only applicable for supergroups and channels. It can be any of the followings: “all” - all kind of members, “kicked” - kicked (banned) members only, “restricted” - restricted members only, “bots” - bots only, “recent” - recent members only, “administrators” - chat administrators only. Only applicable to supergroups and channels. Defaults to “recent”.

1

Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members on channels.

2

A query string is applicable only for “all”, “kicked” and “restricted” filters only.

Example

# Get first 200 recent members
for member in chat.get_members():
    print(member.user.first_name)

# Get all administrators
for member in chat.iter_members(filter="administrators"):
    print(member.user.first_name)

# Get first 3 bots
for member in chat.iter_members(filter="bots", limit=3):
    print(member.user.first_name)
Returns

Generator – A generator yielding ChatMember objects.