Skip to main content
// Kick a member from group
CometChat.kickGroupMember(
  guid: "GROUP_ID",
  uid: "USER_ID",
  onSuccess: (String message) => debugPrint("Kicked: $message"),
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);

// Ban a member from group
CometChat.banGroupMember(
  guid: "GROUP_ID",
  uid: "USER_ID",
  onSuccess: (String message) => debugPrint("Banned: $message"),
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);

// Unban a member
CometChat.unbanGroupMember(
  guid: "GROUP_ID",
  uid: "USER_ID",
  onSuccess: (String message) => debugPrint("Unbanned: $message"),
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);

// Fetch banned members
BannedGroupMembersRequest request = (BannedGroupMembersRequestBuilder(guid: "GUID")
  ..limit = 30
).build();
request.fetchNext(
  onSuccess: (List<GroupMember> members) => debugPrint("Banned: $members"),
  onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
);
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. 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
All of the above actions can only be performed by the Admin or the Moderator of the group.
Available via: SDK | REST API | UI Kits

Kick a Group Member

The Admin or Moderator of a group can kick a member out of the group using the kickGroupMember() method.
String uid= "cometchat-uid-3";
String guid = "GUID";
CometChat.kickGroupMember(guid: guid,uid: uid,
  onSuccess: (String message) {
    debugPrint("Group Member Kicked  Successfully : $message");
  }, onError: (CometChatException e) {
    debugPrint("Group Member Kicked failed  : ${e.message}");
  });
The kickGroupMember() takes following parameters:
ParameterTypeDescription
guidStringThe GUID of the group from which user is to be kicked
uidStringThe UID of the user to be kicked
onSuccessFunction(String)Callback triggered on successful kick
onErrorFunction(CometChatException)Callback triggered on error
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 — A String message confirming the member was kicked:
ParameterTypeDescriptionSample Value
messagestringSuccess confirmation message"cometchat-uid-3 kicked successfully"
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_NOT_A_MEMBER"
messagestringHuman-readable error message"The user is not a member of this group."
detailsstringAdditional technical details"Please verify the user ID and group ID and try again."

Ban a Group Member

The Admin or Moderator of the group can ban a member from the group using the banGroupMember() method. Unlike kicked users, banned users cannot rejoin until unbanned.
String uid= "cometchat-uid-3";
String guid = "GUID";
CometChat.banGroupMember(guid: guid,uid: uid,
                       onSuccess: (String message) {
                         debugPrint("Group Member Banned  Successfully : $message");
                       },onError: (CometChatException e) {
                         debugPrint("Group Member Ban failed  : ${e.message}");
                       });
The banGroupMember() method takes the following parameters:
ParameterTypeDescription
guidStringThe GUID of the group from which user is to be banned
uidStringThe UID of the user to be banned
onSuccessFunction(String)Callback triggered on successful ban
onErrorFunction(CometChatException)Callback triggered on error
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 — A String message confirming the member was banned:
ParameterTypeDescriptionSample Value
messagestringSuccess confirmation message"cometchat-uid-3 banned successfully"
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_NOT_A_MEMBER"
messagestringHuman-readable error message"The user is not a member of this group."
detailsstringAdditional technical details"Please verify the user ID and group ID and try again."

Unban a Banned Group Member from a Group

Only Admin or Moderators of the group can unban a previously banned member from the group using the unbanGroupMember() method.
String uid= "cometchat-uid-3";
String guid = "GUID";
CometChat.unbanGroupMember(guid: guid,uid: uid,
                         onSuccess: (String message) {
                           debugPrint("Group Member Unbanned  Successfully : $message");
                         },
                         onError: (CometChatException e) {
                           debugPrint("Group Member Unban failed  : ${e.message}");
                         });
The unbanGroupMember() method takes the following parameters
ParameterTypeDescription
guidStringThe GUID of the group from which user is to be unbanned
uidStringThe UID of the user to be unbanned
onSuccessFunction(String)Callback triggered on successful unban
onErrorFunction(CometChatException)Callback triggered on error
The unbanned user can now rejoin the group.
On Success — A String message confirming the member was unbanned:
ParameterTypeDescriptionSample Value
messagestringSuccess confirmation message"cometchat-uid-3 unbanned successfully"
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_NOT_A_MEMBER"
messagestringHuman-readable error message"The user is not a member of this group."
detailsstringAdditional technical details"Please verify the user ID and group ID and try again."

Get List of Banned Members for a Group

In order to fetch the list of banned groups members for a group, you can use the BannedGroupMembersRequest class. To use this class i.e to create an object of the BannedGroupMembersRequest class, you need to use the BannedGroupMembersRequestBuilder class. The BannedGroupMembersRequestBuilder class allows you to set the parameters based on which the banned group members are to be fetched. The BannedGroupMembersRequestBuilder class allows you to set the below parameters: The GUID of the group for which the banned members are to be fetched must be specified in the constructor of the GroupMembersRequestBuilder class.

Set Limit

This method sets the limit i.e. the number of banned members that should be fetched in a single iteration.
BannedGroupMembersRequestBuilder builder = BannedGroupMembersRequestBuilder(guid: conversationWith);
BannedGroupMembersRequest  bannedGroupMembersRequest = (builder
     ..limit = 50
     ).build();

Set Search Keyword

This method allows you to set the search string based on which the banned group members are to be fetched.
BannedGroupMembersRequestBuilder builder = BannedGroupMembersRequestBuilder(guid: conversationWith);
BannedGroupMembersRequest  bannedGroupMembersRequest = (builder
     ..limit = 50
     ..searchKeyword = "abc"
     ).build();
Finally, once all the parameters are set to the builder class, you need to call the build() method to get the object of the BannedGroupMembersRequest class. Once you have the object of the BannedGroupMembersRequest class, you need to call the fetchNext() method. Calling this method will return a list of GroupMember objects containing n number of banned members where n is the limit set in the builder class.
BannedGroupMembersRequestBuilder builder = BannedGroupMembersRequestBuilder(guid: conversationWith);
BannedGroupMembersRequest  bannedGroupMembersRequest = (builder
     ..limit = 50
     ).build();

bannedGroupMembersRequest.fetchNext( onSuccess: (List<GroupMember> groupMembers) {
        debugPrint("Banned Group Members Fetched Successfully : $groupMembers");
      },onError: (CometChatException e) {
        debugPrint("Banned Group Members Fetch failed with exception: ${e.message}");
      });
On Success — A List<GroupMember> containing the banned group members for the specified group (each item is a GroupMember object):GroupMember Object (per item in array):
ParameterTypeDescriptionSample Value
uidstringUnique identifier of the user"cometchat-uid-3"
namestringDisplay name of the user"Kevin Hart"
linkstringProfile linknull
avatarstringAvatar URL"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"
metadataobjectCustom metadata{}
statusstringOnline status"offline"
rolestringUser role"default"
statusMessagestringStatus messagenull
tagsarrayUser tags[]
hasBlockedMebooleanWhether this user has blocked the current userfalse
blockedByMebooleanWhether the current user has blocked this userfalse
lastActiveAtnumberEpoch timestamp of last activity1745554700
scopestringMember scope in the group"participant"
joinedAtnumberEpoch timestamp when the member joined the group1745550000
ParameterTypeDescriptionSample Value
codestringError code identifier"ERR_NOT_A_MEMBER"
messagestringHuman-readable error message"The user is not a member of this group."
detailsstringAdditional technical details"Please verify the group ID and try again."

Real-Time Group Member Kicked/Banned Events

In other words, as a member of a group, how do I know when someone is banned/kicked when my app is running? 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
class Class_Name  with GroupListener {

//CometChat.addGroupListener("group_Listener_id", this);

@override
void onGroupMemberKicked(Action action, User kickedUser, User kickedBy, Group kickedFrom) {
  print("onGroupMemberKicked ");
}
void onGroupMemberBanned(Action action, User bannedUser, User bannedBy, Group bannedFrom) {

  print("onGroupMemberBanned ");
}

@override
void onGroupMemberUnbanned(Action action, User unbannedUser, User unbannedBy, Group unbannedFrom) {
  print("onGroupMemberUnbanned ");
}
}
Always remove group listeners when they’re no longer needed (e.g., in the dispose() method). Failing to remove listeners can cause memory leaks and duplicate event handling.
CometChat.removeGroupListener("group_Listener_id");

Missed Group Member Kicked/Banned Events

In other words, as a member of a group, how do I know when someone is banned/kicked when my app is not running? When you retrieve the list of previous messages if a member has been kicked/banned/unbanned from any group that the logged-in user is a member of, the list of messages will contain an Action message. An Action message is a sub-class of BaseMessage class. Kicked event:
FieldValue/TypeDescription
action"kicked"The action type
actionByUserThe user who kicked the member
actionOnUserThe member who was kicked
actionForGroupThe group from which the member was kicked
Banned event:
FieldValue/TypeDescription
action"banned"The action type
actionByUserThe user who banned the member
actionOnUserThe member who was banned
actionForGroupThe group from which the member was banned
Unbanned event:
FieldValue/TypeDescription
action"unbanned"The action type
actionByUserThe user who unbanned the member
actionOnUserThe member who was unbanned
actionForGroupThe group from which the member was unbanned

Next Steps

Add Members

Add new members to your groups

Change Member Scope

Update member roles and permissions

Retrieve Group Members

Fetch the list of members in a group

Leave a Group

Allow members to leave a group