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

# Join A Group

> Join CometChat public and password-protected groups in JavaScript apps using group GUID, type, and password.

## Join a Group

Use `joinGroup()` to join a group.

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

    const password: string = "";
    const groupType: string = CometChat.GROUP_TYPE.PUBLIC;

    CometChat.joinGroup(GUID, groupType, password).then(
    (group: CometChat.Group) => {
    console.log("Group joined successfully:", group);
    }, (error: CometChat.CometChatException) => {
    console.log("Group joining failed with exception:", error);
    }
    );

    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const GUID = "GUID";
    const password = "";
    const groupType = CometChat.GROUP_TYPE.PUBLIC;

    CometChat.joinGroup(GUID, groupType, password).then(
    group => {
      console.log("Group joined successfully:", group);
    }, error => {
      console.log("Group joining failed with exception:", error);
    }
    );
    ```
  </Tab>
</Tabs>

| Parameter   | Description                                             |
| ----------- | ------------------------------------------------------- |
| `GUID`      | The GUID of the group to join                           |
| `groupType` | `CometChat.GROUP_TYPE.PUBLIC`, `PASSWORD`, or `PRIVATE` |
| `password`  | Required for password-protected groups                  |

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.

The method returns a [`Group`](/sdk/reference/entities#group) object with `hasJoined` set to `true`.

## Real-time Group Member Joined Events

Register a `GroupListener` to receive events when members join.

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    CometChat.addGroupListener(
      "UNIQUE_LISTENER_ID",
      new CometChat.GroupListener({
          onGroupMemberJoined: (message: CometChat.Action, joinedUser: CometChat.User, joinedGroup: CometChat.Group) => {
              console.log("User joined", { message, joinedUser, joinedGroup });
          }
      })
    );
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    CometChat.addGroupListener(
      "UNIQUE_LISTENER_ID",
      new CometChat.GroupListener({
          onGroupMemberJoined: (message, joinedUser, joinedGroup) => {
              console.log("User joined", { message, joinedUser, joinedGroup });
          }
      })
    );
    ```
  </Tab>
</Tabs>

<Warning>
  Always remove group listeners when they're no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.

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

## Missed Group Member Joined Events

When fetching message history, join events appear as [`Action`](/sdk/reference/messages#action) messages with:

* `action` — `"joined"`
* `actionBy` — [`User`](/sdk/reference/entities#user) who joined
* `actionFor` — [`Group`](/sdk/reference/entities#group) that was joined

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Leave a Group" icon="right-from-bracket" href="/sdk/javascript/leave-group">
    Allow members to leave a group
  </Card>

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

  <Card title="Send Messages" icon="paper-plane" href="/sdk/javascript/send-message">
    Send messages to group conversations
  </Card>

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