Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

// Kick a member
CometChat.kickGroupMember(UID: "UID", GUID: "GUID", onSuccess: { response in }, onError: { error in })

// Ban a member
CometChat.banGroupMember(UID: "UID", GUID: "GUID", onSuccess: { response in }, onError: { error in })

// Unban a member
CometChat.unbanGroupMember(UID: "UID", GUID: "GUID", onSuccess: { response in }, onError: { error in })

// Fetch banned members
let request = BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(guid: "GUID")
    .set(limit: 30).build()
request.fetchNext(onSuccess: { members in }, onError: { error in })
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.
ParameterDescription
UIDThe UID of the user to be kicked
GUIDThe 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.

Ban a Group Member

Admins or Moderators can ban a member using banGroupMember(). Unlike kicked users, banned users cannot rejoin until unbanned.
ParameterDescription
UIDThe UID of the user to be banned
GUIDThe 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.

Unban a Group Member

Admins or Moderators can unban a previously banned member using unbanGroupMember().
ParameterDescription
UIDThe UID of the user to be unbanned
GUIDThe 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)")
})
Once unbanned, the user can rejoin the group.

Get List of Banned Members for a Group

Use BannedGroupMembersRequestBuilder 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 bannedGroupMembersRequest = BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(guid: "cometchat-guid-1")
    .set(limit: 30)
    .build()

Set Search Keyword

Filters banned members by a search string.
let bannedGroupMembersRequest = BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(guid: "cometchat-guid-1")
    .set(limit: 30)
    .set(searchKeyword: "abc")
    .build()
Once configured, call build() to create the request, then fetchNext() to retrieve banned members.
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)")
})

Real-Time Kick/Ban/Unban Events

Implement these CometChatGroupDelegate methods to receive real-time notifications:
MethodTriggered When
onGroupMemberKicked()A member is kicked
onGroupMemberBanned()A member is banned
onGroupMemberUnbanned()A member is unbanned
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 ?? "")")
    }
}
Set delegate in viewDidLoad(): CometChat.groupdelegate = self. Remove delegate when view is dismissed to avoid memory leaks.

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