> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-ios-ui-kit-sdk-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Kick Member From A Group

> Guide to kicking, banning, and unbanning group members using the CometChat iOS SDK (admin/moderator only).

<Info>
  **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](/sdk/ios/group-add-members) · [Change Member Scope](/sdk/ios/group-change-member-scope) · [Groups Overview](/sdk/ios/groups-overview)
</Info>

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

<Warning>All the above-mentioned actions can only be performed by the **Admin** or the **Moderator** of the group.</Warning>

### Kick vs Ban Comparison

| Action | Can Rejoin? | Appears in Banned List? |
| ------ | ----------- | ----------------------- |
| Kick   | Yes         | No                      |
| Ban    | No          | Yes (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.

| Parameter | Type   | Description                                           |
| --------- | ------ | ----------------------------------------------------- |
| UID       | String | The UID of the user to be kicked                      |
| GUID      | String | The GUID of the group from which user is to be kicked |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    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)")
    })
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    NSString *UID = @"cometchat-uid-2";
    NSString *GUID = @"cometchat-guid-1";

    [CometChat kickGroupMemberWithUID:UID GUID:GUID onSuccess:^(NSString * response) {
        NSLog(@"%@ kicked from the group %@ successfully", UID, GUID);
    } onError:^(CometChatException * error) {
        NSLog(@"Error: %@", [error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

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.

<Accordion title="Sample Payload - Kick Member">
  **Request Parameters:**

  | Parameter | Type   | Description                                                         |
  | --------- | ------ | ------------------------------------------------------------------- |
  | UID       | String | Unique identifier of the user to kick. Example: `"cometchat-uid-2"` |
  | GUID      | String | Unique identifier of the group. Example: `"cometchat-guid-1"`       |

  **Success Response:**

  | Parameter | Type   | Description                                                                          |
  | --------- | ------ | ------------------------------------------------------------------------------------ |
  | response  | String | Success message. Example: `"cometchat-uid-2 is kicked from the group successfully."` |

  **After Kick:**

  | Effect      | Description                                       |
  | ----------- | ------------------------------------------------- |
  | Membership  | User is removed from the group                    |
  | Rejoin      | User CAN rejoin the group                         |
  | Banned List | User does NOT appear in banned list               |
  | Event       | Other members receive `onGroupMemberKicked` event |

  **Error Response ([CometChatException](#common-error-codes)):**

  | Parameter        | Type   | Description                                                                                               |
  | ---------------- | ------ | --------------------------------------------------------------------------------------------------------- |
  | errorCode        | String | Unique error code. Example: `"ERR_GROUP_NOT_JOINED"`                                                      |
  | errorDescription | String | Human-readable error message. Example: `"The user with UID cometchat-uid-2 is not a member of the group"` |
</Accordion>

***

## Ban a Group Member

The Admin or Moderator of the group can ban a member from the group using the `banGroupMember()` method.

| Parameter | Type   | Description                                           |
| --------- | ------ | ----------------------------------------------------- |
| UID       | String | The UID of the user to be banned                      |
| GUID      | String | The GUID of the group from which user is to be banned |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    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)")
    })
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    NSString *UID = @"cometchat-uid-2";
    NSString *GUID = @"cometchat-guid-1";

    [CometChat banGroupMemberWithUID:UID GUID:GUID onSuccess:^(NSString * response) {
        NSLog(@"%@ banned from the group %@ successfully", UID, GUID);
    } onError:^(CometChatException * error) {
        NSLog(@"Error: %@", [error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

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.

<Accordion title="Sample Payload - Ban Member">
  **Request Parameters:**

  | Parameter | Type   | Description                                                        |
  | --------- | ------ | ------------------------------------------------------------------ |
  | UID       | String | Unique identifier of the user to ban. Example: `"cometchat-uid-2"` |
  | GUID      | String | Unique identifier of the group. Example: `"cometchat-guid-1"`      |

  **Success Response:**

  | Parameter | Type   | Description                                                                          |
  | --------- | ------ | ------------------------------------------------------------------------------------ |
  | response  | String | Success message. Example: `"cometchat-uid-2 is banned from the group successfully."` |

  **After Ban:**

  | Effect      | Description                                       |
  | ----------- | ------------------------------------------------- |
  | Membership  | User is removed from the group                    |
  | Rejoin      | User CANNOT rejoin until unbanned                 |
  | Banned List | User appears in banned members list               |
  | Event       | Other members receive `onGroupMemberBanned` event |

  **Error Response ([CometChatException](#common-error-codes)):**

  | Parameter        | Type   | Description                                                           |
  | ---------------- | ------ | --------------------------------------------------------------------- |
  | errorCode        | String | Unique error code. Example: `"ERR_CANNOT_BAN_OWNER"`                  |
  | errorDescription | String | Human-readable error message. Example: `"Cannot ban the group owner"` |
</Accordion>

***

## 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.

| Parameter | Type   | Description                                             |
| --------- | ------ | ------------------------------------------------------- |
| UID       | String | The UID of the user to be unbanned                      |
| GUID      | String | The GUID of the group from which user is to be unbanned |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    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)")
    })
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    NSString *UID = @"cometchat-uid-2";
    NSString *GUID = @"cometchat-guid-1";

    [CometChat unbanGroupMemberWithUID:UID GUID:GUID onSuccess:^(NSString * response) {
        NSLog(@"%@ unbanned from the group %@ successfully", UID, GUID);
    } onError:^(CometChatException * error) {
        NSLog(@"Error: %@", [error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

The unbanned user can now rejoin the group.

<Accordion title="Sample Payload - Unban Member">
  **Request Parameters:**

  | Parameter | Type   | Description                                                          |
  | --------- | ------ | -------------------------------------------------------------------- |
  | UID       | String | Unique identifier of the user to unban. Example: `"cometchat-uid-2"` |
  | GUID      | String | Unique identifier of the group. Example: `"cometchat-guid-1"`        |

  **Success Response:**

  | Parameter | Type   | Description                                                                            |
  | --------- | ------ | -------------------------------------------------------------------------------------- |
  | response  | String | Success message. Example: `"cometchat-uid-2 is unbanned from the group successfully."` |

  **After Unban:**

  | Effect      | Description                                         |
  | ----------- | --------------------------------------------------- |
  | Banned List | User is removed from banned list                    |
  | Rejoin      | User can now rejoin the group                       |
  | Event       | Other members receive `onGroupMemberUnbanned` event |

  **Error Response ([CometChatException](#common-error-codes)):**

  | Parameter        | Type   | Description                                                               |
  | ---------------- | ------ | ------------------------------------------------------------------------- |
  | errorCode        | String | Unique error code. Example: `"ERR_USER_NOT_BANNED"`                       |
  | errorDescription | String | Human-readable error message. Example: `"User is not in the banned list"` |
</Accordion>

***

## 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

| Method                | Parameter | Returns                          | Description             |
| --------------------- | --------- | -------------------------------- | ----------------------- |
| `init(guid:)`         | String    | BannedGroupMembersRequestBuilder | Constructor with GUID   |
| `set(limit:)`         | Int       | BannedGroupMembersRequestBuilder | Number to fetch (1-100) |
| `set(searchKeyword:)` | String    | BannedGroupMembersRequestBuilder | Search keyword          |
| `build()`             | -         | BannedGroupMembersRequest        | Build request           |

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    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)")
    })
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    NSString *GUID = @"cometchat-guid-1";
    NSInteger limit = 30;

    BannedGroupMembersRequest *bannedGroupMemberRequest = [[[[BannedGroupMembersRequestBuilder alloc]initWithGuid:GUID] setLimitWithLimit:limit] build];

    [bannedGroupMemberRequest fetchNextOnSuccess:^(NSArray<GroupMember *> * bannedMembers) {
        for (GroupMember *member in bannedMembers) {
            NSLog(@"Banned member: %@", [member stringValue]);
        }
    } onError:^(CometChatException * error) {
        NSLog(@"Error: %@", [error errorDescription]);
    }];
    ```
  </Tab>
</Tabs>

<Accordion title="Sample Payload - Fetch Banned Members">
  **Request Parameters:**

  | Parameter | Type   | Description                                              |
  | --------- | ------ | -------------------------------------------------------- |
  | guid      | String | Unique group identifier. Example: `"cometchat-guid-1"`   |
  | limit     | Int    | Maximum number of banned members to fetch. Example: `30` |

  **Success Response (Array of [GroupMember](/sdk/ios/retrieve-group-members#groupmember-object-properties) Objects):**

  | Parameter | Type                             | Description                                                                   |
  | --------- | -------------------------------- | ----------------------------------------------------------------------------- |
  | uid       | String?                          | Unique identifier of the banned member. Example: `"banned-user1"`             |
  | name      | String?                          | Display name of the member. Example: `"Banned User"`                          |
  | avatar    | String?                          | URL to the member's avatar image. Example: `"https://example.com/avatar.png"` |
  | scope     | [MemberScope](#memberscope-enum) | Member's scope before ban. Example: `.participant`                            |
  | joinedAt  | Double                           | Unix timestamp when member originally joined. Example: `1699700000.0`         |

  **Sample Banned Member Entries:**

  | uid          | name           | scope        | joinedAt     |
  | ------------ | -------------- | ------------ | ------------ |
  | banned-user1 | Banned User    | .participant | 1699700000.0 |
  | banned-user2 | Another Banned | .participant | 1699750000.0 |

  **Error Response ([CometChatException](#common-error-codes)):**

  | Parameter        | Type   | Description                                                                      |
  | ---------------- | ------ | -------------------------------------------------------------------------------- |
  | errorCode        | String | Unique error code. Example: `"ERR_GROUP_NOT_JOINED"`                             |
  | errorDescription | String | Human-readable error message. Example: `"The user is not a member of the group"` |
</Accordion>

***

## Real-Time Group Member Kicked/Banned Events

In order to receive user Events for kick/ban/unban you must add protocol conformance `CometChatGroupDelegate`:

<Tabs>
  <Tab title="Swift">
    ```swift theme={null}
    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 ?? "")")
        }
    }
    ```
  </Tab>

  <Tab title="Objective C">
    ```objc theme={null}
    @interface ViewController ()<CometChatGroupDelegate>
    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        [CometChat setGroupdelegate:self];
    }

    - (void)onGroupMemberKickedWithAction:(Action *)action kickedUser:(User *)kickedUser kickedBy:(User *)kickedBy kickedFrom:(Group *)kickedFrom {
        // User was kicked
    }

    - (void)onGroupMemberBannedWithAction:(Action *)action bannedUser:(User *)bannedUser bannedBy:(User *)bannedBy bannedFrom:(Group *)bannedFrom {
        // User was banned
    }

    - (void)onGroupMemberUnbannedWithAction:(Action *)action unbannedUser:(User *)unbannedUser unbannedBy:(User *)unbannedBy unbannedFrom:(Group *)unbannedFrom {
        // User was unbanned
    }

    @end
    ```
  </Tab>
</Tabs>

<Accordion title="Sample Payload - onGroupMemberKicked Event">
  **Event Trigger:** Received via `CometChatGroupDelegate.onGroupMemberKicked(action:kickedUser:kickedBy:kickedFrom:)`

  **ActionMessage Object:**

  | Parameter | Type                                               | Description                                                                      |
  | --------- | -------------------------------------------------- | -------------------------------------------------------------------------------- |
  | action    | String                                             | Action type. Example: `"kicked"`                                                 |
  | actionBy  | [User](/sdk/ios/users-overview#user-properties)    | User who performed the kick. Example: `{"uid": "admin-uid", "name": "Admin"}`    |
  | actionOn  | [User](/sdk/ios/users-overview#user-properties)    | User who was kicked. Example: `{"uid": "user123", "name": "John"}`               |
  | actionFor | [Group](/sdk/ios/retrieve-groups#group-properties) | Group where action occurred. Example: `{"guid": "group123", "name": "My Group"}` |

  **kickedUser ([User](/sdk/ios/users-overview#user-properties) Object):**

  | Parameter | Type    | Description                                                |
  | --------- | ------- | ---------------------------------------------------------- |
  | uid       | String? | Unique identifier of the kicked user. Example: `"user123"` |
  | name      | String? | Display name of the user. Example: `"John Doe"`            |

  **kickedBy ([User](/sdk/ios/users-overview#user-properties) Object):**

  | Parameter | Type    | Description                                                      |
  | --------- | ------- | ---------------------------------------------------------------- |
  | uid       | String? | Unique identifier of the admin/moderator. Example: `"admin-uid"` |
  | name      | String? | Display name of the admin/moderator. Example: `"Admin User"`     |

  **kickedFrom ([Group](/sdk/ios/retrieve-groups#group-properties) Object):**

  | Parameter    | Type    | Description                                       |
  | ------------ | ------- | ------------------------------------------------- |
  | guid         | String  | Unique group identifier. Example: `"group123"`    |
  | name         | String? | Group display name. Example: `"My Group"`         |
  | membersCount | Int     | Updated member count (decremented). Example: `14` |
</Accordion>

<Accordion title="Sample Payload - onGroupMemberBanned Event">
  **Event Trigger:** Received via `CometChatGroupDelegate.onGroupMemberBanned(action:bannedUser:bannedBy:bannedFrom:)`

  **ActionMessage Object:**

  | Parameter | Type                                               | Description                      |
  | --------- | -------------------------------------------------- | -------------------------------- |
  | action    | String                                             | Action type. Example: `"banned"` |
  | actionBy  | [User](/sdk/ios/users-overview#user-properties)    | User who performed the ban       |
  | actionOn  | [User](/sdk/ios/users-overview#user-properties)    | User who was banned              |
  | actionFor | [Group](/sdk/ios/retrieve-groups#group-properties) | Group where action occurred      |

  **bannedUser ([User](/sdk/ios/users-overview#user-properties) Object):**

  | Parameter | Type    | Description                                                |
  | --------- | ------- | ---------------------------------------------------------- |
  | uid       | String? | Unique identifier of the banned user. Example: `"user123"` |
  | name      | String? | Display name of the user. Example: `"John Doe"`            |
</Accordion>

<Accordion title="Sample Payload - onGroupMemberUnbanned Event">
  **Event Trigger:** Received via `CometChatGroupDelegate.onGroupMemberUnbanned(action:unbannedUser:unbannedBy:unbannedFrom:)`

  **ActionMessage Object:**

  | Parameter | Type                                               | Description                        |
  | --------- | -------------------------------------------------- | ---------------------------------- |
  | action    | String                                             | Action type. Example: `"unbanned"` |
  | actionBy  | [User](/sdk/ios/users-overview#user-properties)    | User who performed the unban       |
  | actionOn  | [User](/sdk/ios/users-overview#user-properties)    | User who was unbanned              |
  | actionFor | [Group](/sdk/ios/retrieve-groups#group-properties) | Group where action occurred        |

  **unbannedUser ([User](/sdk/ios/users-overview#user-properties) Object):**

  | Parameter | Type    | Description                                                  |
  | --------- | ------- | ------------------------------------------------------------ |
  | uid       | String? | Unique identifier of the unbanned user. Example: `"user123"` |
  | name      | String? | Display name of the user. Example: `"John Doe"`              |
</Accordion>

## 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.

| Event    | action       | actionBy          | actionOn              | actionFor |
| -------- | ------------ | ----------------- | --------------------- | --------- |
| Kicked   | `"kicked"`   | User who kicked   | User who was kicked   | Group     |
| Banned   | `"banned"`   | User who banned   | User who was banned   | Group     |
| Unbanned | `"unbanned"` | User who unbanned | User who was unbanned | Group     |

***

## MemberScope Enum

| Scope        | Raw Value     | Description                              |
| ------------ | ------------- | ---------------------------------------- |
| .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 Code               | Description                              | Resolution                          |
| ------------------------ | ---------------------------------------- | ----------------------------------- |
| ERR\_GROUP\_NOT\_FOUND   | Group with specified GUID does not exist | Verify the GUID is correct          |
| ERR\_UID\_NOT\_FOUND     | User with specified UID does not exist   | Verify the user UID                 |
| ERR\_GROUP\_NOT\_JOINED  | User is not a member of the group        | Join the group first                |
| ERR\_NOT\_A\_MEMBER      | Target user is not a member of the group | User must be a member               |
| ERR\_PERMISSION\_DENIED  | Logged-in user is not admin or moderator | Only admin/moderator can kick/ban   |
| ERR\_CANNOT\_KICK\_OWNER | Cannot kick the group owner              | Owner must transfer ownership first |
| ERR\_CANNOT\_BAN\_OWNER  | Cannot ban the group owner               | Owner must transfer ownership first |
| ERR\_USER\_NOT\_BANNED   | User is not in the banned list           | User must be banned to unban        |
