Skip to main content
// Kick a member
await CometChat.kickGroupMember("GUID", "UID");

// Ban a member
await CometChat.banGroupMember("GUID", "UID");

// Unban a member
await CometChat.unbanGroupMember("GUID", "UID");

// Fetch banned members
const request = new CometChat.BannedMembersRequestBuilder("GUID").setLimit(30).build();
const bannedMembers = await request.fetchNext();
Remove members from a group by kicking or banning them. Kicked users can rejoin; banned users cannot until they’re unbanned. Only admins and moderators can perform these actions.

Kick a Group Member

Admins or Moderators can remove a member using kickGroupMember(). The kicked user can rejoin the group later.
let GUID: string = "GUID";
let UID: string = "UID";

CometChat.kickGroupMember(GUID, UID).then(
  (response: boolean) => {
      console.log("Group member kicked successfully", response);
  }, (error: CometChat.CometChatException) => {
      console.log("Group member kicking failed with error", error);
  }
);
The kickGroupMember() takes the following parameters:
ParameterDescription
UIDThe UID of the user to be kicked.
GUIDThe GUID of the group from which user is to be kicked
The kicked user will be no longer part of the group and can not perform any actions in the group, but the kicked user can rejoin the group. On success, the method resolves with a boolean value (true) confirming the operation.

Ban a Group Member

Admins or Moderators can ban a member using banGroupMember(). Unlike kicked users, banned users cannot rejoin until unbanned.
let GUID: string = "GUID";
let UID: string = "UID";

CometChat.banGroupMember(GUID, UID).then(
  (response: boolean) => {
      console.log("Group member banned successfully", response);
  }, (error: CometChat.CometChatException) => {
      console.log("Group member banning failed with error", error);
  }
);
The banGroupMember() method takes the following parameters:
ParameterDescription
UIDThe UID of the user to be banned
GUIDThe GUID of the group from which user is to be banned
The banned user will be no longer part of the group and can not perform any actions in the group. A banned user cannot rejoin the same group without being unbanned. On success, the method resolves with a boolean value (true) confirming the operation.

Unban a Group Member

Admins or Moderators can unban a previously banned member using unbanGroupMember().
let GUID: string = "GUID";
let UID: string = "UID";

CometChat.unbanGroupMember(GUID, UID).then(
  (response: boolean) => {
      console.log("Group member unbanned successfully", response);
  }, (error: CometChat.CometChatException) => {
      console.log("Group member unbanning failed with error", error);
  }
);
The unbanGroupMember() method takes the following parameters
ParameterDescription
UIDThe UID of the user to be unbanned
GUIDThe GUID of the group from which user is to be unbanned
Once unbanned, the user can rejoin the group. On success, the method resolves with a boolean value (true) confirming the operation.

Get List of Banned Members for a Group

Use BannedMembersRequestBuilder to fetch banned members of a Group. The GUID must be specified in the constructor.

Set Limit

Sets the number of banned members to fetch per request.
let GUID: string = "GUID";
let limit: number = 30;
let bannedGroupMembersRequest: CometChat.BannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
  .setLimit(limit)
  .build();

Set Search Keyword

Filters banned members by a search string.
let GUID: string = "GUID";
let limit: number = 30;
let searchKeyword: string = "super";
let bannedGroupMembersRequest: CometChat.BannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
  .setLimit(limit)
  .setSearchKeyword(searchKeyword)
  .build();
Once configured, call build() to create the request, then fetchNext() to retrieve banned members.
let GUID: string = "GUID";
let limit: number = 30;
let bannedGroupMembersRequest: CometChat.BannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
  .setLimit(limit)
  .build();

bannedGroupMembersRequest.fetchNext().then(
  (bannedMembers: CometChat.GroupMember[]) => {
      console.log("Banned Group Member list fetched successfully:", bannedMembers);
  }, (error: CometChat.CometChatException) => {
      console.log("Banned Group Member list fetching failed with exception:", error);
  }
);
The fetchNext() method returns an array of GroupMember objects representing the banned members of the group.

Real-Time Kick/Ban/Unban Events

Implement these GroupListener methods to receive real-time notifications:
MethodTriggered When
onGroupMemberKicked()A member is kicked
onGroupMemberBanned()A member is banned
onGroupMemberUnbanned()A member is unbanned
let listenerID: string = "UNIQUE_LISTENER_ID";

CometChat.addGroupListener(
  listenerID,
  new CometChat.GroupListener({
      onGroupMemberKicked: (message: CometChat.Action, kickedUser: CometChat.User, kickedBy: CometChat.User, kickedFrom: CometChat.Group) => {
          console.log("User kicked", { message, kickedUser, kickedBy, kickedFrom });
      },
      onGroupMemberBanned: (message: CometChat.Action, bannedUser: CometChat.User, bannedBy: CometChat.User, bannedFrom: CometChat.Group) => {
          console.log("User banned", { message, bannedUser, bannedBy, bannedFrom });
      },
      onGroupMemberUnbanned: (message: CometChat.Action, unbannedUser: CometChat.User, unbannedBy: CometChat.User, unbannedFrom: CometChat.Group) => {
          console.log("User unbanned", { message, unbannedUser, unbannedBy, unbannedFrom });
      }
  })
);
Always remove group listeners when they’re no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.
CometChat.removeGroupListener("UNIQUE_LISTENER_ID");

Missed Group Member Kicked/Banned Events

When fetching previous messages, kick/ban/unban actions appear as Action messages (a subclass of BaseMessage). Kicked event:
FieldValue/TypeDescription
action"kicked"The action type
actionByUserThe user who kicked the member
actionOnUserThe member who was kicked
actionForGroupThe group
Banned event:
FieldValue/TypeDescription
action"banned"The action type
actionByUserThe user who banned the member
actionOnUserThe member who was banned
actionForGroupThe group
Unbanned event:
FieldValue/TypeDescription
action"unbanned"The action type
actionByUserThe user who unbanned the member
actionOnUserThe member who was unbanned
actionForGroupThe group

Next Steps

Add Members

Add new members to a group

Change Member Scope

Promote or demote group members

Retrieve Group Members

Fetch the list of members in a group

Leave a Group

Allow members to leave a group