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

# Join A Group

> Learn how to join public and password-protected groups using the CometChat Flutter SDK.

<Accordion title="AI Integration Quick Reference">
  ```dart theme={null}
  // Join a public group
  CometChat.joinGroup("GROUP_GUID", CometChatGroupType.public,
    onSuccess: (Group group) => debugPrint("Joined: ${group.name}"),
    onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
  );

  // Join a password-protected group
  CometChat.joinGroup("GROUP_GUID", CometChatGroupType.password,
    password: "group_password",
    onSuccess: (Group group) => debugPrint("Joined: ${group.name}"),
    onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
  );
  ```

  **Group types:** `CometChatGroupType.public` | `CometChatGroupType.password` | `CometChatGroupType.private`
</Accordion>

Join a group to start sending and receiving messages in it. Public groups can be joined freely, password groups require the correct password, and private groups require an admin to add you (no direct join).

## Join a Group

Use `joinGroup()` to join a group.

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

### Parameters

| Parameter   | Type                                  | Description                                                                                 |
| ----------- | ------------------------------------- | ------------------------------------------------------------------------------------------- |
| `guid`      | `String`                              | The GUID of the group to join                                                               |
| `groupType` | `String`                              | `CometChatGroupType.public`, `CometChatGroupType.password`, or `CometChatGroupType.private` |
| `password`  | `String`                              | Required for password-protected groups (defaults to empty string)                           |
| `onSuccess` | `Function(Group group)?`              | Callback triggered on successful join                                                       |
| `onError`   | `Function(CometChatException excep)?` | Callback triggered on error                                                                 |

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String GUID = "GUID";
    String groupType = CometChatGroupType.public;
    String password = "";

    CometChat.joinGroup(GUID, groupType, password: password,
                      onSuccess: (Group group) {
                        debugPrint("Group Joined Successfully : $group ");
                      }, onError: (CometChatException e) {
                        debugPrint("Group Joining failed with exception: ${e.message}");
      });
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — A `Group` object containing all details of the joined group:

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

  **Group Object:**

  | Parameter           | Type    | Description                                              | Sample Value         |
  | ------------------- | ------- | -------------------------------------------------------- | -------------------- |
  | `guid`              | string  | Unique identifier for the group                          | `"cometchat-guid-1"` |
  | `name`              | string  | Display name of the group                                | `"Hello Group!"`     |
  | `icon`              | string  | URL of the group icon                                    | `null`               |
  | `description`       | string  | Description of the group                                 | `null`               |
  | `membersCount`      | number  | Number of members in the group                           | `5`                  |
  | `metadata`          | object  | Custom metadata attached to the group                    | `{}`                 |
  | `joinedAt`          | number  | Epoch timestamp when the logged-in user joined the group | `1745554729`         |
  | `hasJoined`         | boolean | Whether the logged-in user has joined the group          | `true`               |
  | `createdAt`         | number  | Epoch timestamp when the group was created               | `1745551200`         |
  | `owner`             | string  | UID of the group owner                                   | `"cometchat-uid-1"`  |
  | `updatedAt`         | number  | Epoch timestamp when the group was last updated          | `1745554729`         |
  | `tags`              | array   | List of tags associated with the group                   | `[]`                 |
  | `type`              | string  | Type of the group (public, private, password)            | `"public"`           |
  | `scope`             | string  | Scope of the logged-in user in the group                 | `"participant"`      |
  | `password`          | string  | Password for password-protected groups                   | `null`               |
  | `isBannedFromGroup` | boolean | Whether the logged-in user is banned from the group      | `false`              |
</Accordion>

<Accordion title="Error">
  | Parameter | Type   | Description                  | Sample Value                                   |
  | --------- | ------ | ---------------------------- | ---------------------------------------------- |
  | `code`    | string | Error code identifier        | `"ERR_GUID_NOT_FOUND"`                         |
  | `message` | string | Human-readable error message | `"The specified group does not exist."`        |
  | `details` | string | Additional technical details | `"Please provide a valid GUID for the group."` |
</Accordion>

Once joined, you can send and receive messages in the group. CometChat tracks joined groups — you don't need to rejoin each session. Check `hasJoined` on the [`Group`](/sdk/reference/entities#group) object to verify membership.

## Real-time Group Member Joined Events

*In other words, as a member of a group, how do I know if someone joins the group when my app is running?*

If a user joins any group, the members of the group receive a real-time event in the `onGroupMemberJoined()` method of the `GroupListener` class.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    class ClassName with GroupListener {
      // CometChat.addGroupListener("group_Listener_id", this);

      @override
      void onGroupMemberJoined(Action action, User joinedUser, Group joinedGroup) {
        debugPrint("onGroupMemberJoined");
      }
    }
    ```
  </Tab>
</Tabs>

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

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

## Missed Group Member Joined Events

*In other words, as a member of a group, how do I know if someone joins the group when my app is not running?*

When you retrieve the list of previous messages if a member has joined 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 the group member joined event, in the `Action` object received, the following fields can help you get the relevant information-

1. `action` - `joined`
2. `actionBy` - User object containing the details of the user who joined the group
3. `actionFor`- Group object containing the details of the group the user has joined

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Leave a Group" icon="right-from-bracket" href="/sdk/flutter/leave-group">
    Allow members to leave a group
  </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="Send Messages" icon="paper-plane" href="/sdk/flutter/send-message">
    Send messages to group conversations
  </Card>

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