Chat Members

Chat members are represented by ChatMember objects. Each object contains the member and their status in the chat.

Listing Members

Use getChatMembers to list the members of a group, supergroup, or channel.

const members = await client.getChatMembers(chatId);

for (const { member, status } of members) {
  console.log(member.id, status);
}

Use getChatMember to retrieve one member.

const member = await client.getChatMember(chatId, userId);

Handling Membership Changes

The chatMember update contains the previous and current state of a member.

client.on("chatMember", (ctx) => {
  const { oldChatMember, newChatMember } = ctx.update.chatMember;
  console.log(oldChatMember.status, newChatMember.status);
});

Use the myChatMember update to handle changes to the current account’s membership.

Restricting a Member

Use setChatMemberRights to restrict a member of a supergroup.

await client.setChatMemberRights(chatId, userId, {
  rights: {
    canSendMessages: false,
  },
});

Set until to a future Unix timestamp in seconds to make the restriction temporary.

Promoting a Member

Use promoteChatMember to grant administrator rights.

await client.promoteChatMember(chatId, userId, {
  canDeleteMessages: true,
  canManageTopics: true,
});

Removing a Member

Ban a member to prevent them from rejoining. Unban them to allow them to join again.

await client.banChatMember(chatId, userId);
await client.unbanChatMember(chatId, userId);

Use kickChatMember to remove a member without keeping them banned.

await client.kickChatMember(chatId, userId);