Skip to main content
Quick Reference for AI Agents & Developers
  • Kick member: CometChat.kickGroupMember(UID:GUID:onSuccess:onError:)
  • Ban member: CometChat.banGroupMember(UID:GUID:onSuccess:onError:)
  • Unban member: CometChat.unbanGroupMember(UID:GUID:onSuccess:onError:)
  • Fetch banned: BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(guid:).build()
  • Permission: Only admin or moderator can perform these actions
  • Related: Add Members · Change Member Scope · Groups Overview
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 the above-mentioned actions can only be performed by the Admin or the Moderator of the group.

Kick vs Ban Comparison

ActionCan Rejoin?Appears in Banned List?
KickYesNo
BanNoYes (until unbanned)

Kick a Group Member

The Admin or Moderator of the group can kick a member out of the group using the kickGroupMember() method.
ParameterTypeDescription
UIDStringThe UID of the user to be kicked
GUIDStringThe GUID of the group from which user is to be kicked
let uid = "cometchat-uid-2"
let guid = "cometchat-guid-1"

CometChat.kickGroupMember(UID: uid, GUID: guid, onSuccess: { (response) in
    print("\(uid) is kicked from the group \(guid) successfully.")
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})
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.
Request Parameters:
ParameterTypeDescription
UIDStringUnique identifier of the user to kick. Example: "cometchat-uid-2"
GUIDStringUnique identifier of the group. Example: "cometchat-guid-1"
Success Response:
ParameterTypeDescription
responseStringSuccess message. Example: "cometchat-uid-2 is kicked from the group successfully."
After Kick:
EffectDescription
MembershipUser is removed from the group
RejoinUser CAN rejoin the group
Banned ListUser does NOT appear in banned list
EventOther members receive onGroupMemberKicked event
Error Response (CometChatException):
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_GROUP_NOT_JOINED"
errorDescriptionStringHuman-readable error message. Example: "The user with UID cometchat-uid-2 is not a member of the group"

Ban a Group Member

The Admin or Moderator of the group can ban a member from the group using the banGroupMember() method.
ParameterTypeDescription
UIDStringThe UID of the user to be banned
GUIDStringThe GUID of the group from which user is to be banned
let uid = "cometchat-uid-2"
let guid = "cometchat-guid-1"

CometChat.banGroupMember(UID: uid, GUID: guid, onSuccess: { (response) in
    print("\(uid) is banned from the group \(guid) successfully.")
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})
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.
Request Parameters:
ParameterTypeDescription
UIDStringUnique identifier of the user to ban. Example: "cometchat-uid-2"
GUIDStringUnique identifier of the group. Example: "cometchat-guid-1"
Success Response:
ParameterTypeDescription
responseStringSuccess message. Example: "cometchat-uid-2 is banned from the group successfully."
After Ban:
EffectDescription
MembershipUser is removed from the group
RejoinUser CANNOT rejoin until unbanned
Banned ListUser appears in banned members list
EventOther members receive onGroupMemberBanned event
Error Response (CometChatException):
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_CANNOT_BAN_OWNER"
errorDescriptionStringHuman-readable error message. Example: "Cannot ban the group owner"

Unban a Banned Group Member

Only Admin or Moderators of the group can unban a previously banned member from the group using the unbanGroupMember() method.
ParameterTypeDescription
UIDStringThe UID of the user to be unbanned
GUIDStringThe GUID of the group from which user is to be unbanned
let uid = "cometchat-uid-2"
let guid = "cometchat-guid-1"

CometChat.unbanGroupMember(UID: uid, GUID: guid, onSuccess: { (response) in
    print("\(uid) is unbanned from the group \(guid) successfully.")
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})
The unbanned user can now rejoin the group.
Request Parameters:
ParameterTypeDescription
UIDStringUnique identifier of the user to unban. Example: "cometchat-uid-2"
GUIDStringUnique identifier of the group. Example: "cometchat-guid-1"
Success Response:
ParameterTypeDescription
responseStringSuccess message. Example: "cometchat-uid-2 is unbanned from the group successfully."
After Unban:
EffectDescription
Banned ListUser is removed from banned list
RejoinUser can now rejoin the group
EventOther members receive onGroupMemberUnbanned event
Error Response (CometChatException):
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_USER_NOT_BANNED"
errorDescriptionStringHuman-readable error message. Example: "User is not in the banned list"

Get List of Banned Members

In order to fetch the list of banned groups members for a group, you can use the BannedGroupMembersRequest class.

BannedGroupMembersRequestBuilder Methods

MethodParameterReturnsDescription
init(guid:)StringBannedGroupMembersRequestBuilderConstructor with GUID
set(limit:)IntBannedGroupMembersRequestBuilderNumber to fetch (1-100)
set(searchKeyword:)StringBannedGroupMembersRequestBuilderSearch keyword
build()-BannedGroupMembersRequestBuild request
let limit = 30
let guid = "cometchat-guid-1"

let bannedGroupMembersRequest = BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(guid: guid)
    .set(limit: limit)
    .build()

bannedGroupMembersRequest.fetchNext(onSuccess: { (groupMembers) in
    for bannedMember in groupMembers {
        print("Banned member: \(bannedMember.stringValue())")
    }
}, onError: { (error) in
    print("Error: \(error?.errorDescription)")
})
Request Parameters:
ParameterTypeDescription
guidStringUnique group identifier. Example: "cometchat-guid-1"
limitIntMaximum number of banned members to fetch. Example: 30
Success Response (Array of GroupMember Objects):
ParameterTypeDescription
uidString?Unique identifier of the banned member. Example: "banned-user1"
nameString?Display name of the member. Example: "Banned User"
avatarString?URL to the member’s avatar image. Example: "https://example.com/avatar.png"
scopeMemberScopeMember’s scope before ban. Example: .participant
joinedAtDoubleUnix timestamp when member originally joined. Example: 1699700000.0
Sample Banned Member Entries:
uidnamescopejoinedAt
banned-user1Banned User.participant1699700000.0
banned-user2Another Banned.participant1699750000.0
Error Response (CometChatException):
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_GROUP_NOT_JOINED"
errorDescriptionStringHuman-readable error message. Example: "The user is not a member of the group"

Real-Time Group Member Kicked/Banned Events

In order to receive user Events for kick/ban/unban you must add protocol conformance CometChatGroupDelegate:
class ViewController: UIViewController, CometChatGroupDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        CometChat.groupdelegate = self
    }
    
    func onGroupMemberKicked(action: ActionMessage, kickedUser: User, kickedBy: User, kickedFrom: Group) {
        print("\(kickedUser.name ?? "") kicked from \(kickedFrom.name ?? "") by \(kickedBy.name ?? "")")
    }
    
    func onGroupMemberBanned(action: ActionMessage, bannedUser: User, bannedBy: User, bannedFrom: Group) {
        print("\(bannedUser.name ?? "") banned from \(bannedFrom.name ?? "") by \(bannedBy.name ?? "")")
    }
    
    func onGroupMemberUnbanned(action: ActionMessage, unbannedUser: User, unbannedBy: User, unbannedFrom: Group) {
        print("\(unbannedUser.name ?? "") unbanned from \(unbannedFrom.name ?? "") by \(unbannedBy.name ?? "")")
    }
}
Event Trigger: Received via CometChatGroupDelegate.onGroupMemberKicked(action:kickedUser:kickedBy:kickedFrom:)ActionMessage Object:
ParameterTypeDescription
actionStringAction type. Example: "kicked"
actionByUserUser who performed the kick. Example: {"uid": "admin-uid", "name": "Admin"}
actionOnUserUser who was kicked. Example: {"uid": "user123", "name": "John"}
actionForGroupGroup where action occurred. Example: {"guid": "group123", "name": "My Group"}
kickedUser (User Object):
ParameterTypeDescription
uidString?Unique identifier of the kicked user. Example: "user123"
nameString?Display name of the user. Example: "John Doe"
kickedBy (User Object):
ParameterTypeDescription
uidString?Unique identifier of the admin/moderator. Example: "admin-uid"
nameString?Display name of the admin/moderator. Example: "Admin User"
kickedFrom (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "group123"
nameString?Group display name. Example: "My Group"
membersCountIntUpdated member count (decremented). Example: 14
Event Trigger: Received via CometChatGroupDelegate.onGroupMemberBanned(action:bannedUser:bannedBy:bannedFrom:)ActionMessage Object:
ParameterTypeDescription
actionStringAction type. Example: "banned"
actionByUserUser who performed the ban
actionOnUserUser who was banned
actionForGroupGroup where action occurred
bannedUser (User Object):
ParameterTypeDescription
uidString?Unique identifier of the banned user. Example: "user123"
nameString?Display name of the user. Example: "John Doe"
Event Trigger: Received via CometChatGroupDelegate.onGroupMemberUnbanned(action:unbannedUser:unbannedBy:unbannedFrom:)ActionMessage Object:
ParameterTypeDescription
actionStringAction type. Example: "unbanned"
actionByUserUser who performed the unban
actionOnUserUser who was unbanned
actionForGroupGroup where action occurred
unbannedUser (User Object):
ParameterTypeDescription
uidString?Unique identifier of the unbanned user. Example: "user123"
nameString?Display name of the user. Example: "John Doe"

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.
EventactionactionByactionOnactionFor
Kicked"kicked"User who kickedUser who was kickedGroup
Banned"banned"User who bannedUser who was bannedGroup
Unbanned"unbanned"User who unbannedUser who was unbannedGroup

MemberScope Enum

ScopeRaw ValueDescription
.admin”admin”Full group management privileges
.moderator”moderator”Can kick/ban members, delete messages
.participant”participant”Default scope, can send/receive messages

Common Error Codes

Error CodeDescriptionResolution
ERR_GROUP_NOT_FOUNDGroup with specified GUID does not existVerify the GUID is correct
ERR_UID_NOT_FOUNDUser with specified UID does not existVerify the user UID
ERR_GROUP_NOT_JOINEDUser is not a member of the groupJoin the group first
ERR_NOT_A_MEMBERTarget user is not a member of the groupUser must be a member
ERR_PERMISSION_DENIEDLogged-in user is not admin or moderatorOnly admin/moderator can kick/ban
ERR_CANNOT_KICK_OWNERCannot kick the group ownerOwner must transfer ownership first
ERR_CANNOT_BAN_OWNERCannot ban the group ownerOwner must transfer ownership first
ERR_USER_NOT_BANNEDUser is not in the banned listUser must be banned to unban