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();
There are certain actions that can be performed on the group members:
  1. Kick a member from the group
  2. Ban a member from the group
  3. Unban a member from the group
  4. Update the scope of the member of the group
Only Admins or 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.
const GUID = "GUID";
const UID = "UID";

CometChat.kickGroupMember(GUID, UID).then(
response => {
  console.log("Group member kicked successfully", response);
}, error => {
  console.log("Group member kicking failed with error", error);
}
);
The kickGroupMember() method 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
On success, the method resolves with a success message string.

Ban a Group Member

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

CometChat.banGroupMember(GUID, UID).then(
response => {
  console.log("Group member banned successfully", response);
}, error => {
  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
On success, the method resolves with a success message string.

Unban a Banned Group Member from a Group

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

CometChat.unbanGroupMember(GUID, UID).then(
response => {
  console.log("Group member unbanned successfully", response);
}, error => {
  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.

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 = "GUID";
let limit = 30;
let bannedGroupMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
  																.setLimit(limit)
  																.build();

Set Search Keyword

Filters banned members by a search string.
let GUID = "GUID";
let limit = 30;
let searchKeyword = "super";
let bannedGroupMembersRequest = 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 = "GUID";
let limit = 30;
let bannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
  													.setLimit(limit)
  													.build();

bannedMembersRequest.fetchNext().then(
bannedMembers => {
  console.log("Banned Group Member list fetched successfully:", bannedMembers);
}, error => {
  console.log("Banned Group Member list fetching failed with exception:", error);
}
);

Real-Time Group Member Kicked/Banned 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 = "UNIQUE_LISTENER_ID";

CometChat.addGroupListener(
listenerID,
new CometChat.GroupListener({
  onGroupMemberKicked: (message, kickedUser, kickedBy, kickedFrom) => {
    console.log("User kicked", { message, kickedUser, kickedBy, kickedFrom });
  },
  onGroupMemberBanned: (message, bannedUser, bannedBy, bannedFrom) => {
    console.log("User banned", { message, bannedUser, bannedBy, bannedFrom });
  },
  onGroupMemberUnbanned: (message, unbannedUser, unbannedBy,unbannedFrom) => {
    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