Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
// Kick a member (can rejoin)CometChat.kickGroupMember("UID", "GUID", object : CallbackListener<String>() { override fun onSuccess(message: String) { } override fun onError(e: CometChatException) { }})// Ban a member (cannot rejoin without unban)CometChat.banGroupMember("UID", "GUID", callback)// Unban a memberCometChat.unbanGroupMember("UID", "GUID", callback)
Note: Only admins and moderators can kick, ban, or unban members.
Admins and moderators can kick, ban, or unban group members. Kicked users can rejoin; banned users cannot until unbanned.
The Admin or Moderator of the group can ban a member from the group using the banGroupMember() method.
Java
Kotlin
private String UID = "UID";private String GUID = "GUID";CometChat.banGroupMember(UID, GUID, new CometChat.CallbackListener<String>() { @Override public void onSuccess(String successMessage) { Log.d(TAG, "Group member banned successfully"); } @Override public void onError(CometChatException e) { Log.d(TAG, "Group member banning failed with exception: " + e.getMessage()); }});
val GUID:String="GUID"val UID:String="UID"CometChat.banGroupMember(UID,GUID,object:CometChat.CallbackListener<String>(){ override fun onSuccess(p0: String?) { Log.d(TAG, "Group member banned successfully") } override fun onError(p0: CometChatException?) { Log.d(TAG, "Group member banning failed with exception: " + p0?.message) }})
The banGroupMember() method takes the following parameters:
Parameter
Description
UID
The UID of the user to be banned
GUID
The 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 group same group without being unbanned.
After configuring the builder, call build() then fetchNext() to retrieve banned members.
Java
Kotlin
private BannedGroupMembersRequest bannedGroupMembersRequest = null;private String GUID = "GUID";private int limit = 30;bannedGroupMembersRequest = new BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(GUID).setLimit(limit).build();bannedGroupMembersRequest.fetchNext(new CometChat.CallbackListener<List<GroupMember>>(){ @Override public void onSuccess(List <GroupMember> list) { Log.d(TAG, "Banned Group Member list fetched successfully: " + list.size()); } @Override public void onError(CometChatException e) { Log.d(TAG, "Banned Group Member list fetching failed with exception: " + e.getMessage()); }});
var bannedGroupMembersRequest:BannedGroupMembersRequest?=nullval GUID:String="GUID"val limit:Int=30bannedGroupMembersRequest=BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(GUID).setLimit(limit).build()bannedGroupMembersRequest?.fetchNext(object :CometChat.CallbackListener<List<GroupMember>>(){ override fun onSuccess(p0: List<GroupMember>?) { Log.d(TAG, "Banned Group Member list fetched successfully: " + p0?.size) } override fun onError(p0: CometChatException?) { Log.d(TAG, "Banned Group Member list fetching failed with exception: " + p0?.message) }})
When a member is kicked, banned, or unbanned, group members receive real-time events via the GroupListener class. The callbacks provide an Action object, the affected User, the acting User, and the Group.
Java
Kotlin
CometChat.addGroupListener(GroupChatActivity.class.getSimpleName(), new CometChat.GroupListener() { @Override public void onGroupMemberKicked(Action action, User kickedUser, User kickedBy, Group kickedFrom) { } @Override public void onGroupMemberBanned(Action action, User bannedUser, User bannedBy, Group bannedFrom) { } @Override public void onGroupMemberUnbanned(Action action, User unbannedUser, User unbannedBy, Group unbannedFrom) { }});
When fetching message history, kick/ban/unban actions appear as Action messages with these fields:
action - kicked
actionBy - User object containing the details of the user who has kicked the member
actionOn - User object containing the details of the member that has been kicked
actionFor - Group object containing the details of the Group from which the member was kicked
For group member banned event, the details can be obtained using the below fields of the Action class-
action - banned
actionBy - User object containing the details of the user who has banned the member
actionOn - User object containing the details of the member that has been banned
actionFor - Group object containing the details of the Group from which the member was banned
For group member unbanned event, the details can be obtained using the below fields of the Action class-
action - unbanned
actionBy - User object containing the details of the user who has unbanned the member
actionOn - User object containing the details of the member that has been unbanned
actionFor - Group object containing the details of the Group from which the member was unbanned
Always remove group listeners when they’re no longer needed (e.g., in onDestroy() or when navigating away). Failing to remove listeners can cause memory leaks and duplicate event handling.