Skip to main content
Quick Reference for AI Agents & Developers
  • Join group: CometChat.joinGroup(GUID:groupType:password:onSuccess:onError:)
  • Public groups: No password required
  • Password groups: Password required
  • Private groups: Cannot join directly — must be added by admin/owner
  • Related: Create Group · Leave Group · Groups Overview

Join a Group

In order to start participating in group conversations, you will have to join a group. You can do so using the joinGroup() method.

Join Group Parameters

ParameterTypeDescription
GUIDStringUnique group identifier
groupTypeGroupType.public, .private, or .password
passwordString?Required for .password groups

Group Type Behavior

TypeCan Join DirectlyPassword Required
.publicYesNo
.passwordYesYes
.privateNoN/A (must be added by admin)
let guid = "cometchat-guid-11"
let password: String? = nil // mandatory in case of password protected group type

CometChat.joinGroup(GUID: guid, groupType: .public, password: nil, onSuccess: { (group) in
    print("Group joined successfully. " + group.stringValue())
}, onError: { (error) in
    print("Group joining failed with error:" + error!.errorDescription)
})
Request Parameters:
ParameterTypeDescription
GUIDStringUnique group identifier. Example: "cometchat-guid-1"
groupTypeGroupTypeType of group. Example: .public
passwordString?Password for the group. Example: nil
Success Response (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "cometchat-guid-1"
nameString?Group display name. Example: "Hiking Group"
groupTypeGroupTypeType of group. Example: .public
iconString?URL to the group’s icon image. Example: "https://assets.cometchat.io/sampleapp/v2/groups/cometchat-guid-1.webp"
groupDescriptionString?Description of the group. Example: "Explore, connect, and chat with fellow outdoor enthusiasts"
ownerString?UID of the group owner. Example: "cometchat-uid-5"
membersCountIntTotal number of members (incremented by 1). Example: 6
hasJoinedBoolWhether the logged-in user is a member. Example: true
joinedAtIntUnix timestamp when user joined. Example: 1772113500
scopeMemberScopeUser’s scope in the group. Example: .participant
createdAtIntUnix timestamp when group was created. Example: 1753861429
tags[String]Array of tags. Example: []
metadata[String: Any]?Custom metadata dictionary. Example: [:]
Success Response Properties After Join:
PropertyValue After JoinDescription
hasJoinedtrueUser is now a member
joinedAtUnix timestampTime of joining
scope.participantDefault scope for new members
membersCountIncremented by 1Updated member count
Error Response (CometChatException):
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_ALREADY_JOINED"
errorDescriptionStringHuman-readable error message. Example: "User is already a member of this group"
Request Parameters:
ParameterTypeDescription
GUIDStringUnique group identifier. Example: "cometchat-guid-1"
groupTypeGroupTypeType of group. Example: .password
passwordStringPassword for the group (required). Example: "test123"
Success Response (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "cometchat-guid-1"
nameString?Group display name. Example: "Secret Group"
groupTypeGroupTypeType of group. Example: .password
iconString?URL to the group’s icon image. Example: nil
groupDescriptionString?Description of the group. Example: nil
ownerString?UID of the group owner. Example: "cometchat-uid-5"
membersCountIntTotal number of members. Example: 5
hasJoinedBoolWhether the logged-in user is a member. Example: true
joinedAtIntUnix timestamp when user joined. Example: 1772113600
scopeMemberScopeUser’s scope in the group. Example: .participant
createdAtIntUnix timestamp when group was created. Example: 1753861429
tags[String]Array of tags. Example: []
metadata[String: Any]?Custom metadata dictionary. Example: [:]
Error Response - Wrong Password:
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_WRONG_GROUP_PASS"
errorDescriptionStringHuman-readable error message. Example: "Incorrect password for password-protected group"
Request Parameters:
ParameterTypeDescription
GUIDStringUnique group identifier. Example: "cometchat-guid-1"
groupTypeGroupTypeType of group. Example: .private
passwordString?Password for the group. Example: nil
Error Response:
ParameterTypeDescription
errorCodeStringUnique error code. Example: "ERR_GROUP_JOIN_NOT_ALLOWED"
errorDescriptionStringHuman-readable error message. Example: "The private groups cannot be joined. Users need to be added to such groups."
Private groups cannot be joined directly. Users must be added by an admin or owner.
Once you have joined a group successfully, you can send and receive messages in that group.
CometChat keeps a track of the groups joined and you do not need to join the group every time you want to communicate in the group. You can identify if a group is joined using the hasJoined parameter in the Group object.

Real-time Group Member Joined Events

In other words, as a recipient, how do I know when someone joins a group? To receive Real-Time Events for the same, you need to implement the onGroupMemberJoined() method of the CometChatGroupDelegate.
class ViewController: UIViewController, CometChatGroupDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        CometChat.groupdelegate = self
    }
    
    func onGroupMemberJoined(action: ActionMessage, joinedUser: User, joinedGroup: Group) {
        print("\(joinedUser.name ?? "") joined \(joinedGroup.name ?? "")")
    }
    
    func onMemberAddedToGroup(action: ActionMessage, addedBy: User, addedUser: User, addedTo: Group) {
        print("\(addedUser.name ?? "") was added to \(addedTo.name ?? "")")
    }
}
Event Trigger: Received via CometChatGroupDelegate.onGroupMemberJoined(action:joinedUser:joinedGroup:)ActionMessage Object:
ParameterTypeDescription
actionStringAction type. Example: "joined"
actionByUserUser who performed the action. Example: {"uid": "user123", "name": "John"}
actionForGroupGroup where action occurred. Example: {"guid": "group123", "name": "My Group"}
joinedUser (User Object):
ParameterTypeDescription
uidString?Unique identifier of the user who joined. Example: "user123"
nameString?Display name of the user. Example: "John Doe"
avatarString?URL to the user’s avatar image. Example: "https://example.com/avatar.png"
statusUserStatusCurrent online status. Example: .online
joinedGroup (Group Object):
ParameterTypeDescription
guidStringUnique group identifier. Example: "group123"
nameString?Group display name. Example: "My Group"
membersCountIntUpdated member count. Example: 16

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:
FieldValueDescription
action"joined"Action type
actionByUser objectUser who joined the group
actionForGroup objectGroup the user joined

GroupType Enum

ValueDescription
.publicAnyone can join without approval
.privateRequires invitation or approval to join
.passwordRequires password to join

MemberScope Enum

ValueDescription
.adminFull control over group
.moderatorCan manage members and messages
.participantRegular member with basic permissions

Common Error Codes

Error CodeDescriptionResolution
ERR_NOT_LOGGED_INUser is not logged inLogin first using CometChat.login()
ERR_GUID_NOT_FOUNDGroup does not existVerify the GUID is correct
ERR_ALREADY_JOINEDAlready a member of this groupNo action needed
ERR_WRONG_GROUP_PASSIncorrect passwordProvide correct password
ERR_GROUP_JOIN_NOT_ALLOWEDCannot join private groupRequest admin to add you
ERR_USER_BANNEDUser is banned from groupContact group admin