> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-v6-beta2-flutter-uikit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Kick Member From A Group

> Learn how to kick, ban, and unban group members using the CometChat React Native SDK, including fetching banned member lists and handling real-time events.

<Info>
  **Quick Reference**

  ```javascript theme={null}
  // Kick a member
  CometChat.kickGroupMember("GUID", "UID");

  // Ban a member
  CometChat.banGroupMember("GUID", "UID");

  // Unban a member
  CometChat.unbanGroupMember("GUID", "UID");

  // Fetch banned members
  let request = new CometChat.BannedMembersRequestBuilder("GUID").setLimit(30).build();
  request.fetchNext();
  ```
</Info>

<Note>
  Available via: [SDK](/sdk/react-native/group-kick-ban-members) | REST API: [Kick](/rest-api/group-members/kick), [Ban](/rest-api/banned-users/ban)
</Note>

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 actions can only be performed by the **Admin** or the **Moderator** of the group.

## Kick a Group Member

The Admin or Moderator of a group can kick a member out of the group using the `kickGroupMember()` method.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    var GUID = "GUID";
    var UID = "UID";

    CometChat.kickGroupMember(GUID, UID).then(
      (response) => {
        console.log("Group member kicked successfully", response);
      },
      (error) => {
        console.log("Group member kicking failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let GUID: string = "GUID";
    let UID: string = "UID";

    CometChat.kickGroupMember(GUID, UID).then(
      (response: Object) => {
        console.log("Group member kicked successfully", response);
      },
      (error: CometChat.CometChatException) => {
        console.log("Group member kicking failed with error", error);
      }
    );
    ```
  </Tab>
</Tabs>

The `kickGroupMember()` takes following parameters

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

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="Response">
  **On Success** — `kickGroupMember()` returns a boolean:

  | Parameter  | Type    | Description                                          | Sample Value |
  | ---------- | ------- | ---------------------------------------------------- | ------------ |
  | `response` | boolean | Indicates whether the member was successfully kicked | `true`       |
</Accordion>

## Ban a Group Member

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

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    var GUID = "GUID";
    var UID = "UID";

    CometChat.banGroupMember(GUID, UID).then(
      (response) => {
        console.log("Group member banned successfully", response);
      },
      (error) => {
        console.log("Group member banning failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let GUID: string = "GUID";
    let UID: string = "UID";

    CometChat.banGroupMember(GUID, UID).then(
      (response: Object) => {
        console.log("Group member banned successfully", response);
      },
      (error: CometChat.CometChatException) => {
        console.log("Group member banning failed with error", error);
      }
    );
    ```
  </Tab>
</Tabs>

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 same group without being unbanned.

<Accordion title="Response">
  **On Success** — `banGroupMember()` returns a boolean:

  | Parameter  | Type    | Description                                          | Sample Value |
  | ---------- | ------- | ---------------------------------------------------- | ------------ |
  | `response` | boolean | Indicates whether the member was successfully banned | `true`       |
</Accordion>

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

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    var GUID = "GUID";
    var UID = "UID";

    CometChat.unbanGroupMember(GUID, UID).then(
      (response) => {
        console.log("Group member unbanned successfully", response);
      },
      (error) => {
        console.log("Group member unbanning failed with error", error);
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let GUID: string = "GUID";
    let UID: string = "UID";

    CometChat.unbanGroupMember(GUID, UID).then(
      (response: Object) => {
        console.log("Group member unbanned successfully", response);
      },
      (error: CometChat.CometChatException) => {
        console.log("Group member unbanning failed with error", error);
      }
    );
    ```
  </Tab>
</Tabs>

The `unbanGroupMember()` method takes the following parameters

| Parameter | Description                                          |
| --------- | ---------------------------------------------------- |
| `UID`     | The UID of the user to be unbanned.                  |
| `GUID`    | The UID of the group from which user is to be banned |

The unbanned user can now rejoin the group.

<Accordion title="Response">
  **On Success** — `unbanGroupMember()` returns a boolean:

  | Parameter  | Type    | Description                                            | Sample Value |
  | ---------- | ------- | ------------------------------------------------------ | ------------ |
  | `response` | boolean | Indicates whether the member was successfully unbanned | `true`       |
</Accordion>

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

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let GUID = "GUID";
    let limit = 30;
    let bannedGroupMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
      .setLimit(limit)
      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let GUID: string = "GUID";
    let limit: number = 30;
    let bannedGroupMembersRequest: CometChat.BannedMembersRequest =
      new CometChat.BannedMembersRequestBuilder(GUID).setLimit(limit).build();
    ```
  </Tab>
</Tabs>

### Set Search Keyword

This method allows you to set the search string based on which the banned group members are to be fetched.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let GUID = "GUID";
    let limit = 30;
    let searchKeyword = "super";
    let bannedGroupMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
      .setLimit(limit)
      .setSearchKeyword(searchKeyword)
      .build();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let GUID: string = "GUID";
    let limit: number = 30;
    let searchKeyword: string = "super";
    let bannedGroupMembersRequest: CometChat.BannedMembersRequest =
      new CometChat.BannedMembersRequestBuilder(GUID)
        .setLimit(limit)
        .setSearchKeyword(searchKeyword)
        .build();
    ```
  </Tab>
</Tabs>

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.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let GUID = "GUID";
    let limit = 30;
    let bannedMembersRequest = new CometChat.BannedMembersRequestBuilder(GUID)
      .setLimit(limit)
      .build();

    bannedMembersRequest.fetchNext().then(
      (bannedMembers) => {
        console.log(
          "Banned Group Member list fetched successfully:",
          bannedMembers
        );
      },
      (error) => {
        console.log(
          "Banned Group Member list fetching failed with exception:",
          error
        );
      }
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let GUID: string = "GUID";
    let limit: number = 30;
    let bannedGroupMembersRequest: CometChat.BannedMembersRequest =
      new CometChat.BannedMembersRequestBuilder(GUID).setLimit(limit).build();

    bannedGroupMembersRequest.fetchNext().then(
      (bannedMembers: CometChat.GroupMember[]) => {
        console.log(
          "Banned Group Member list fetched successfully:",
          bannedMembers
        );
      },
      (error: CometChat.CometChatException) => {
        console.log(
          "Banned Group Member list fetching failed with exception:",
          error
        );
      }
    );
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `fetchNext()` returns an array of banned `GroupMember` objects:

  <span id="banned-member-object" style={{scrollMarginTop: '100px'}} />

  **Banned GroupMember Object (per item in array):**

  | Parameter        | Type    | Description                                              | Sample Value                                                            |
  | ---------------- | ------- | -------------------------------------------------------- | ----------------------------------------------------------------------- |
  | `hasBlockedMe`   | boolean | Whether this user has blocked the current user           | `false`                                                                 |
  | `blockedByMe`    | boolean | Whether the current user has blocked this user           | `false`                                                                 |
  | `deactivatedAt`  | number  | Timestamp when user was deactivated (0 if active)        | `0`                                                                     |
  | `uid`            | string  | Unique identifier of the user                            | `"cometchat-uid-6"`                                                     |
  | `joinedAt`       | number  | Unix timestamp when the user originally joined the group | `1772430763`                                                            |
  | `name`           | string  | Display name of the user                                 | `"Ronald Jerry"`                                                        |
  | `avatar`         | string  | URL to user's avatar image                               | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `status`         | string  | User's online status                                     | `"online"`                                                              |
  | `role`           | string  | User's role                                              | `"default"`                                                             |
  | `statusMessage`  | string  | User's status message                                    | `"Testing CometChat SDK"`                                               |
  | `lastActiveAt`   | number  | Unix timestamp of last activity                          | `1772430654`                                                            |
  | `scope`          | string  | Member's scope in the group before being banned          | `"participant"`                                                         |
  | `isBanned`       | boolean | Whether the user is banned from the group                | `true`                                                                  |
  | `conversationId` | string  | Conversation ID between this user and logged-in user     | `"cometchat-uid-6_user_cometchat-uid-7"`                                |
  | `guid`           | string  | GUID of the group                                        | `"group_1772430752261"`                                                 |
</Accordion>

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

In order to get real-time events for the kick/ban/unban group members you need to override the following methods of the `GroupListener` class.

1. `onGroupMemberKicked()` - triggered when any group member has been kicked.
2. `onGroupMemberBanned()` - triggered when any group member has been banned.
3. `onGroupMemberUnbanned()` - triggered when any group member has been unbanned.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let listenerID = "UNIQUE_LISTENER_ID";

    CometChat.addGroupListener(
      listenerID,
      new CometChat.GroupListener({
        onGroupMemberKicked: (message, kickedUser, kickedBy, kickedFrom) => {
          console.log("User kicked", { message, kickedUser, kickedBy, kickedFrom });
        },
        onGroupMemberBanned: (message, bannedUser, bannedBy, bannedFrom) => {
          console.log("User banned", { message, bannedUser, bannedBy, bannedFrom });
        },
        onGroupMemberUnbanned: (
          message,
          unbannedUser,
          unbannedBy,
          unbannedFrom
        ) => {
          console.log("User unbanned", {
            message,
            unbannedUser,
            unbannedBy,
            unbannedFrom,
          });
        },
      })
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let listenerID: string = "UNIQUE_LISTENER_ID";

    CometChat.addGroupListener(
      listenerID,
      new CometChat.GroupListener({
        onGroupMemberKicked: (
          message: CometChat.Action,
          kickedUser: CometChat.User,
          kickedBy: CometChat.User,
          kickedFrom: CometChat.Group
        ) => {
          console.log("User kicked", { message, kickedUser, kickedBy, kickedFrom });
        },
        onGroupMemberBanned: (
          message: CometChat.Action,
          bannedUser: CometChat.User,
          bannedBy: CometChat.User,
          bannedFrom: CometChat.Group
        ) => {
          console.log("User banned", { message, bannedUser, bannedBy, bannedFrom });
        },
        onGroupMemberUnbanned: (
          message: CometChat.Action,
          unbannedUser: CometChat.User,
          unbannedBy: CometChat.User,
          unbannedFrom: CometChat.Group
        ) => {
          console.log("User unbanned", {
            message,
            unbannedUser,
            unbannedBy,
            unbannedFrom,
          });
        },
      })
    );
    ```
  </Tab>
</Tabs>

<Warning>
  Always remove group listeners when the component unmounts to prevent memory leaks.

  ```javascript theme={null}
  CometChat.removeGroupListener("UNIQUE_LISTENER_ID");
  ```
</Warning>

<Accordion title="Response (onGroupMemberBanned)">
  **On Event** — `onGroupMemberBanned` listener receives the following parameters:

  <span id="on-group-member-banned-response" style={{scrollMarginTop: '100px'}} />

  **Listener Parameters:**

  | Parameter    | Type   | Description                      | Sample Value                                     |
  | ------------ | ------ | -------------------------------- | ------------------------------------------------ |
  | `message`    | object | Action message object            | [See `message` Object ↓](#banned-message-object) |
  | `bannedUser` | object | User who was banned              | [See `bannedUser` Object ↓](#banned-user-object) |
  | `bannedBy`   | object | User who performed the ban       | [See `bannedBy` Object ↓](#banned-by-object)     |
  | `bannedFrom` | object | Group from which user was banned | [See `bannedFrom` Object ↓](#banned-from-object) |

  ***

  <span id="banned-message-object" style={{scrollMarginTop: '100px'}} />

  **`message` Object:**

  | Parameter        | Type   | Description                   | Sample Value                         |
  | ---------------- | ------ | ----------------------------- | ------------------------------------ |
  | `id`             | string | Unique message ID             | `"25545"`                            |
  | `conversationId` | string | Conversation ID               | `"group_group_1772430752261"`        |
  | `type`           | string | Message type                  | `"groupMember"`                      |
  | `receiverType`   | string | Receiver type                 | `"group"`                            |
  | `category`       | string | Message category              | `"action"`                           |
  | `action`         | string | Action performed              | `"banned"`                           |
  | `message`        | string | Human-readable action message | `"Henry Marino banned Ronald Jerry"` |
  | `sentAt`         | number | Unix timestamp when sent      | `1772430770`                         |
  | `updatedAt`      | number | Unix timestamp when updated   | `1772430770`                         |

  ***

  <span id="banned-user-object" style={{scrollMarginTop: '100px'}} />

  **`bannedUser` Object:**

  | Parameter       | Type    | Description                                    | Sample Value                                                            |
  | --------------- | ------- | ---------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the banned user           | `"cometchat-uid-6"`                                                     |
  | `name`          | string  | Display name                                   | `"Ronald Jerry"`                                                        |
  | `avatar`        | string  | URL to avatar image                            | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `status`        | string  | Online status                                  | `"online"`                                                              |
  | `role`          | string  | User's role                                    | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity                | `1772430654`                                                            |
  | `hasBlockedMe`  | boolean | Whether this user has blocked the current user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether the current user has blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Timestamp when deactivated (0 if active)       | `0`                                                                     |

  ***

  <span id="banned-by-object" style={{scrollMarginTop: '100px'}} />

  **`bannedBy` Object:**

  | Parameter       | Type    | Description                                    | Sample Value                                                            |
  | --------------- | ------- | ---------------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the user who banned       | `"cometchat-uid-7"`                                                     |
  | `name`          | string  | Display name                                   | `"Henry Marino"`                                                        |
  | `avatar`        | string  | URL to avatar image                            | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-7.webp"` |
  | `status`        | string  | Online status                                  | `"online"`                                                              |
  | `role`          | string  | User's role                                    | `"default"`                                                             |
  | `lastActiveAt`  | number  | Unix timestamp of last activity                | `1772430649`                                                            |
  | `hasBlockedMe`  | boolean | Whether this user has blocked the current user | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether the current user has blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Timestamp when deactivated (0 if active)       | `0`                                                                     |

  ***

  <span id="banned-from-object" style={{scrollMarginTop: '100px'}} />

  **`bannedFrom` Object:**

  | Parameter            | Type    | Description                       | Sample Value                  |
  | -------------------- | ------- | --------------------------------- | ----------------------------- |
  | `guid`               | string  | Unique identifier of the group    | `"group_1772430752261"`       |
  | `name`               | string  | Name of the group                 | `"Hike"`                      |
  | `type`               | string  | Type of the group                 | `"public"`                    |
  | `membersCount`       | number  | Total members in the group        | `1`                           |
  | `hasJoined`          | boolean | Whether logged-in user has joined | `false`                       |
  | `isBanned`           | boolean | Whether logged-in user is banned  | `false`                       |
  | `conversationId`     | string  | Conversation ID for the group     | `"group_group_1772430752261"` |
  | `createdAt`          | number  | Unix timestamp when created       | `1772430752`                  |
  | `owner`              | string  | UID of the group owner            | `"cometchat-uid-7"`           |
  | `updatedAt`          | number  | Unix timestamp when updated       | `1772430763`                  |
  | `onlineMembersCount` | number  | Number of online members          | `2`                           |
</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. An `Action` message is a sub-class of `BaseMessage` class.

For group member kicked event, the details can be obtained using the below fields of the `Action` class-

1. `action` - `kicked`
2. `actionBy` - User object containing the details of the user who has kicked the member
3. `actionOn` - User object containing the details of the member that has been kicked
4. `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-

1. `action` - `banned`
2. `actionBy` - User object containing the details of the user who has banned the member
3. `actionOn` - User object containing the details of the member that has been banned
4. `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-

1. `action` - `unbanned`
2. `actionBy` - User object containing the details of the user who has unbanned the member
3. `actionOn` - User object containing the details of the member that has been unbanned
4. `actionFor` - Group object containing the details of the Group from which the member was unbanned

<AccordionGroup>
  <Accordion title="Best Practices">
    * Always confirm with the user before kicking or banning — these are disruptive actions
    * Use ban for persistent rule violations and kick for temporary removals (kicked users can rejoin)
    * Keep your local member list in sync by handling `onGroupMemberKicked`, `onGroupMemberBanned`, and `onGroupMemberUnbanned` listeners
    * When fetching banned members, use pagination (`fetchNext()`) to handle large lists efficiently
    * Only admins and moderators can perform these actions — check the logged-in user's scope before showing kick/ban UI controls
  </Accordion>

  <Accordion title="Troubleshooting">
    * **ERR\_NOT\_A\_MEMBER**: The logged-in user is not a member of the group. Ensure the user has joined the group first.
    * **ERR\_INSUFFICIENT\_PERMISSIONS**: Only admins or moderators can kick/ban members. Verify the logged-in user's role.
    * **Banned user can still rejoin**: Make sure you used `banGroupMember()` and not `kickGroupMember()` — kicked users can rejoin, banned users cannot.
    * **Unban not working**: Only admins or moderators can unban. Also ensure the user was actually banned (not just kicked).
    * **Listener events not firing**: Confirm you registered a `GroupListener` with the correct listener ID and are handling the right callback methods.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Change Member Scope" icon="user-gear" href="/sdk/react-native/group-change-member-scope">
    Promote or demote group members
  </Card>

  <Card title="Transfer Ownership" icon="arrow-right-arrow-left" href="/sdk/react-native/transfer-group-ownership">
    Transfer group ownership to another member
  </Card>

  <Card title="Retrieve Group Members" icon="users" href="/sdk/react-native/retrieve-group-members">
    Fetch the list of members in a group
  </Card>

  <Card title="Add Members" icon="user-plus" href="/sdk/react-native/group-add-members">
    Add new members to a group
  </Card>
</CardGroup>
