Skip to main content
// Join a public group
await CometChat.joinGroup("GUID", CometChat.GROUP_TYPE.PUBLIC, "");

// Join a password-protected group
await CometChat.joinGroup("GUID", CometChat.GROUP_TYPE.PASSWORD, "password123");

// Listen for member joined events
CometChat.addGroupListener("listener", new CometChat.GroupListener({
  onGroupMemberJoined: (message, joinedUser, joinedGroup) => { }
}));
Join groups to participate in group conversations and receive real-time events when members join.

Join a Group

Use joinGroup() to join a group.
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);
}
);
ParameterDescription
GUIDThe GUID of the group to join
groupTypeCometChat.GROUP_TYPE.PUBLIC, PASSWORD, or PRIVATE
passwordRequired 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 object to verify membership. The method returns a Group object with hasJoined set to true. Access the response data using getter methods:
FieldGetterReturn TypeDescription
guidgetGuid()stringUnique group ID
namegetName()stringDisplay name of the group
typegetType()stringGroup type ("public", "private", or "password")
hasJoinedgetHasJoined()booleanWhether the logged-in user has joined this group
scopegetScope()stringScope of the logged-in user in the group
membersCountgetMembersCount()numberTotal number of members in the group

Real-time Group Member Joined Events

Register a GroupListener to receive events when members join.
CometChat.addGroupListener(
  "UNIQUE_LISTNER_ID",
  new CometChat.GroupListener({
      onGroupMemberJoined: (message, joinedUser, joinedGroup) => {
          console.log("User joined", { message, joinedUser, joinedGroup });
      }
  })
);
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.
CometChat.removeGroupListener("UNIQUE_LISTNER_ID");

Missed Group Member Joined Events

When fetching message history, join events appear as Action messages with:
  • action"joined"
  • actionByUser who joined
  • actionForGroup that was joined

Next Steps

Leave a Group

Allow members to leave a group

Retrieve Group Members

Fetch the list of members in a group

Send Messages

Send messages to group conversations

Add Members

Programmatically add members to a group