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

# Ban Or Kick Member From A Group

> Learn how to kick, ban, and unban members from groups using the CometChat Flutter SDK, including real-time event handling.

<Accordion title="AI Integration Quick Reference">
  ```dart theme={null}
  // Kick a member from group
  CometChat.kickGroupMember(
    guid: "GROUP_ID",
    uid: "USER_ID",
    onSuccess: (String message) => debugPrint("Kicked: $message"),
    onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
  );

  // Ban a member from group
  CometChat.banGroupMember(
    guid: "GROUP_ID",
    uid: "USER_ID",
    onSuccess: (String message) => debugPrint("Banned: $message"),
    onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
  );

  // Unban a member
  CometChat.unbanGroupMember(
    guid: "GROUP_ID",
    uid: "USER_ID",
    onSuccess: (String message) => debugPrint("Unbanned: $message"),
    onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
  );

  // Fetch banned members
  BannedGroupMembersRequest request = (BannedGroupMembersRequestBuilder(guid: "GUID")
    ..limit = 30
  ).build();
  request.fetchNext(
    onSuccess: (List<GroupMember> members) => debugPrint("Banned: $members"),
    onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
  );
  ```
</Accordion>

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.

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

<Note>
  **Available via:** SDK | [REST API](https://api-explorer.cometchat.com) | [UI Kits](/ui-kit/flutter/overview)
</Note>

## 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="Dart">
    ```dart theme={null}
    String uid= "cometchat-uid-3";
    String guid = "GUID";
    CometChat.kickGroupMember(guid: guid,uid: uid,
      onSuccess: (String message) {
        debugPrint("Group Member Kicked  Successfully : $message");
      }, onError: (CometChatException e) {
        debugPrint("Group Member Kicked failed  : ${e.message}");
      });
    ```
  </Tab>
</Tabs>

The `kickGroupMember()` takes following parameters:

| Parameter   | Type                           | Description                                           |
| ----------- | ------------------------------ | ----------------------------------------------------- |
| `guid`      | `String`                       | The GUID of the group from which user is to be kicked |
| `uid`       | `String`                       | The UID of the user to be kicked                      |
| `onSuccess` | `Function(String)`             | Callback triggered on successful kick                 |
| `onError`   | `Function(CometChatException)` | Callback triggered on error                           |

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** — A `String` message confirming the member was kicked:

  | Parameter | Type   | Description                  | Sample Value                            |
  | --------- | ------ | ---------------------------- | --------------------------------------- |
  | `message` | string | Success confirmation message | `"cometchat-uid-3 kicked successfully"` |
</Accordion>

<Accordion title="Error">
  | Parameter | Type   | Description                  | Sample Value                                              |
  | --------- | ------ | ---------------------------- | --------------------------------------------------------- |
  | `code`    | string | Error code identifier        | `"ERR_NOT_A_MEMBER"`                                      |
  | `message` | string | Human-readable error message | `"The user is not a member of this group."`               |
  | `details` | string | Additional technical details | `"Please verify the user ID and group ID and try again."` |
</Accordion>

## Ban a Group Member

The Admin or Moderator of the group can ban a member from the group using the `banGroupMember()` method. Unlike kicked users, banned users cannot rejoin until unbanned.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String uid= "cometchat-uid-3";
    String guid = "GUID";
    CometChat.banGroupMember(guid: guid,uid: uid,
                           onSuccess: (String message) {
                             debugPrint("Group Member Banned  Successfully : $message");
                           },onError: (CometChatException e) {
                             debugPrint("Group Member Ban failed  : ${e.message}");
                           });
    ```
  </Tab>
</Tabs>

The `banGroupMember()` method takes the following parameters:

| Parameter   | Type                           | Description                                           |
| ----------- | ------------------------------ | ----------------------------------------------------- |
| `guid`      | `String`                       | The GUID of the group from which user is to be banned |
| `uid`       | `String`                       | The UID of the user to be banned                      |
| `onSuccess` | `Function(String)`             | Callback triggered on successful ban                  |
| `onError`   | `Function(CometChatException)` | Callback triggered on error                           |

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** — A `String` message confirming the member was banned:

  | Parameter | Type   | Description                  | Sample Value                            |
  | --------- | ------ | ---------------------------- | --------------------------------------- |
  | `message` | string | Success confirmation message | `"cometchat-uid-3 banned successfully"` |
</Accordion>

<Accordion title="Error">
  | Parameter | Type   | Description                  | Sample Value                                              |
  | --------- | ------ | ---------------------------- | --------------------------------------------------------- |
  | `code`    | string | Error code identifier        | `"ERR_NOT_A_MEMBER"`                                      |
  | `message` | string | Human-readable error message | `"The user is not a member of this group."`               |
  | `details` | string | Additional technical details | `"Please verify the user ID and group ID and try again."` |
</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="Dart">
    ```dart theme={null}
    String uid= "cometchat-uid-3";
    String guid = "GUID";
    CometChat.unbanGroupMember(guid: guid,uid: uid,
                             onSuccess: (String message) {
                               debugPrint("Group Member Unbanned  Successfully : $message");
                             },
                             onError: (CometChatException e) {
                               debugPrint("Group Member Unban failed  : ${e.message}");
                             });
    ```
  </Tab>
</Tabs>

The `unbanGroupMember()` method takes the following parameters

| Parameter   | Type                           | Description                                             |
| ----------- | ------------------------------ | ------------------------------------------------------- |
| `guid`      | `String`                       | The GUID of the group from which user is to be unbanned |
| `uid`       | `String`                       | The UID of the user to be unbanned                      |
| `onSuccess` | `Function(String)`             | Callback triggered on successful unban                  |
| `onError`   | `Function(CometChatException)` | Callback triggered on error                             |

The unbanned user can now rejoin the group.

<Accordion title="Response">
  **On Success** — A `String` message confirming the member was unbanned:

  | Parameter | Type   | Description                  | Sample Value                              |
  | --------- | ------ | ---------------------------- | ----------------------------------------- |
  | `message` | string | Success confirmation message | `"cometchat-uid-3 unbanned successfully"` |
</Accordion>

<Accordion title="Error">
  | Parameter | Type   | Description                  | Sample Value                                              |
  | --------- | ------ | ---------------------------- | --------------------------------------------------------- |
  | `code`    | string | Error code identifier        | `"ERR_NOT_A_MEMBER"`                                      |
  | `message` | string | Human-readable error message | `"The user is not a member of this group."`               |
  | `details` | string | Additional technical details | `"Please verify the user ID and group ID and try again."` |
</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="Dart">
    ```dart theme={null}
    BannedGroupMembersRequestBuilder builder = BannedGroupMembersRequestBuilder(guid: conversationWith);
    BannedGroupMembersRequest  bannedGroupMembersRequest = (builder
         ..limit = 50
         ).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="Dart">
    ```dart theme={null}
    BannedGroupMembersRequestBuilder builder = BannedGroupMembersRequestBuilder(guid: conversationWith);
    BannedGroupMembersRequest  bannedGroupMembersRequest = (builder
         ..limit = 50
         ..searchKeyword = "abc"
         ).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`](/sdk/reference/entities#groupmember) objects containing n number of banned members where n is the limit set in the builder class.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    BannedGroupMembersRequestBuilder builder = BannedGroupMembersRequestBuilder(guid: conversationWith);
    BannedGroupMembersRequest  bannedGroupMembersRequest = (builder
         ..limit = 50
         ).build();

    bannedGroupMembersRequest.fetchNext( onSuccess: (List<GroupMember> groupMembers) {
            debugPrint("Banned Group Members Fetched Successfully : $groupMembers");
          },onError: (CometChatException e) {
            debugPrint("Banned Group Members Fetch failed with exception: ${e.message}");
          });
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — A `List<GroupMember>` containing the banned group members for the specified group (each item is a `GroupMember` object):

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

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

  | Parameter       | Type    | Description                                      | Sample Value                                                            |
  | --------------- | ------- | ------------------------------------------------ | ----------------------------------------------------------------------- |
  | `uid`           | string  | Unique identifier of the user                    | `"cometchat-uid-3"`                                                     |
  | `name`          | string  | Display name of the user                         | `"Kevin Hart"`                                                          |
  | `link`          | string  | Profile link                                     | `null`                                                                  |
  | `avatar`        | string  | Avatar URL                                       | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp"` |
  | `metadata`      | object  | Custom metadata                                  | `{}`                                                                    |
  | `status`        | string  | Online status                                    | `"offline"`                                                             |
  | `role`          | string  | User role                                        | `"default"`                                                             |
  | `statusMessage` | string  | Status message                                   | `null`                                                                  |
  | `tags`          | array   | User tags                                        | `[]`                                                                    |
  | `hasBlockedMe`  | boolean | Whether this user has blocked the current user   | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether the current user has blocked this user   | `false`                                                                 |
  | `lastActiveAt`  | number  | Epoch timestamp of last activity                 | `1745554700`                                                            |
  | `scope`         | string  | Member scope in the group                        | `"participant"`                                                         |
  | `joinedAt`      | number  | Epoch timestamp when the member joined the group | `1745550000`                                                            |
</Accordion>

<Accordion title="Error">
  | Parameter | Type   | Description                  | Sample Value                                  |
  | --------- | ------ | ---------------------------- | --------------------------------------------- |
  | `code`    | string | Error code identifier        | `"ERR_NOT_A_MEMBER"`                          |
  | `message` | string | Human-readable error message | `"The user is not a member of this group."`   |
  | `details` | string | Additional technical details | `"Please verify the group ID and try again."` |
</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?*

Implement these `GroupListener` methods to receive real-time notifications:

| Method                    | Triggered When       |
| ------------------------- | -------------------- |
| `onGroupMemberKicked()`   | A member is kicked   |
| `onGroupMemberBanned()`   | A member is banned   |
| `onGroupMemberUnbanned()` | A member is unbanned |

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    class Class_Name  with GroupListener {

    //CometChat.addGroupListener("group_Listener_id", this);

    @override
    void onGroupMemberKicked(Action action, User kickedUser, User kickedBy, Group kickedFrom) {
      print("onGroupMemberKicked ");
    }
    void onGroupMemberBanned(Action action, User bannedUser, User bannedBy, Group bannedFrom) {

      print("onGroupMemberBanned ");
    }

    @override
    void onGroupMemberUnbanned(Action action, User unbannedUser, User unbannedBy, Group unbannedFrom) {
      print("onGroupMemberUnbanned ");
    }
    }
    ```
  </Tab>
</Tabs>

<Warning>
  Always remove group listeners when they're no longer needed (e.g., in the `dispose()` method). Failing to remove listeners can cause memory leaks and duplicate event handling.

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

## 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`](/sdk/reference/messages#action) message. An `Action` message is a sub-class of [`BaseMessage`](/sdk/reference/messages#basemessage) class.

**Kicked event:**

| Field       | Value/Type | Description                                |
| ----------- | ---------- | ------------------------------------------ |
| `action`    | `"kicked"` | The action type                            |
| `actionBy`  | User       | The user who kicked the member             |
| `actionOn`  | User       | The member who was kicked                  |
| `actionFor` | Group      | The group from which the member was kicked |

**Banned event:**

| Field       | Value/Type | Description                                |
| ----------- | ---------- | ------------------------------------------ |
| `action`    | `"banned"` | The action type                            |
| `actionBy`  | User       | The user who banned the member             |
| `actionOn`  | User       | The member who was banned                  |
| `actionFor` | Group      | The group from which the member was banned |

**Unbanned event:**

| Field       | Value/Type   | Description                                  |
| ----------- | ------------ | -------------------------------------------- |
| `action`    | `"unbanned"` | The action type                              |
| `actionBy`  | User         | The user who unbanned the member             |
| `actionOn`  | User         | The member who was unbanned                  |
| `actionFor` | Group        | The group from which the member was unbanned |

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Add Members" icon="user-plus" href="/sdk/flutter/group-add-members">
    Add new members to your groups
  </Card>

  <Card title="Change Member Scope" icon="user-gear" href="/sdk/flutter/group-change-member-scope">
    Update member roles and permissions
  </Card>

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

  <Card title="Leave a Group" icon="right-from-bracket" href="/sdk/flutter/leave-group">
    Allow members to leave a group
  </Card>
</CardGroup>
