> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Members

> Add members to CometChat groups with the Android SDK and assign participant, moderator, or admin scopes.

> [accordion] AI Integration Quick Reference
>
> ```kotlin theme={null}
> // Add members to a group
> val members = listOf(
>     GroupMember("uid1", CometChatConstants.SCOPE_MODERATOR),
>     GroupMember("uid2", CometChatConstants.SCOPE_PARTICIPANT)
> )
>
> CometChat.addMembersToGroup("GUID", members, null, 
>     object : CallbackListener<HashMap<String, String>>() {
>         override fun onSuccess(result: HashMap<String, String>) { }
>         override fun onError(e: CometChatException) { }
>     })
> ```
>
> **Note:** Only admins and moderators can add members. The result HashMap contains UID as key and "success" or error message as value.

## Add Members to Group

Use `addMembersToGroup()` with the group GUID, a list of [`GroupMember`](https://www.cometchat.com/docs/sdk/reference/entities#groupmember) objects, and an optional list of UIDs to ban.

> [tab] Java
>
> ```java theme={null}
> List<GroupMember> members = new ArrayList<>();
> members.add(new GroupMember("uid1",CometChatConstants.SCOPE_MODERATOR));
> members.add(new GroupMember("uid2", CometChatConstants.SCOPE_ADMIN));
>
> CometChat.addMembersToGroup("GUID", members, null, new CometChat.CallbackListener<HashMap<String, String>>(){
>   @Override
>   public void onSuccess(HashMap<String, String> successMap) {
>     Log.d("CometChatActivity", success);
>   }
>
>   @Override
>   public void onError(CometChatException e) {
>     Toast.makeText(CometChatActivity.this, e.getMessage(),Toast.LENGTH_LONG).show();
>   }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val member:MutableList<GroupMember> = arrayListOf()
> member.add(GroupMember(UID,CometChatConstants.SCOPE_PARTICIPANT))
>
> CometChat.addMembersToGroup(GUID,member,null,object :CometChat.CallbackListener<HashMap<String,String>>(){
>
>   override fun onSuccess(p0: HashMap<String, String>?) {
>
>   }
>
>   override fun onError(p0: CometChatException?) {
>
>   }
> })
> ```

In the `onSuccess()` method of the `CallbackListener`, you will receive a HashMap which will contain the `UID` of the users and the value will either be `success` or an error message describing why the operation to add the user to the group or ban the user failed.

## Real-Time Group Member Added Events

When a member is added to a group, existing members receive a real-time event in `onMemberAddedToGroup()` of the `GroupListener` class. The callback provides an [`Action`](https://www.cometchat.com/docs/sdk/reference/messages#action) object, the adding [`User`](https://www.cometchat.com/docs/sdk/reference/entities#user), the added [`User`](https://www.cometchat.com/docs/sdk/reference/entities#user), and the [`Group`](https://www.cometchat.com/docs/sdk/reference/entities#group).

> [!NOTE]
>
> When a member is added by another user, `onMemberAddedToGroup()` fires. When a user joins on their own, `onGroupMemberJoined()` fires instead.

> [tab] Java
>
> ```java theme={null}
> CometChat.addGroupListener("UNIQUE_ID", new CometChat.GroupListener() {
>   @Override
>   public void onMemberAddedToGroup(Action action, User addedby, User userAdded, Group addedTo) {
>     Log.d("onMemberAddedToGroup", action.getMessage());
>   }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.addGroupListener("UNIQUE_ID", object : CometChat.GroupListener() {
>   override fun onMemberAddedToGroup(action: Action, addedby: User, userAdded: User, addedTo: Group) {
>     Log.d("onMemberAddedToGroup", action.message)
>   }
> })
> ```

## Member Added to Group event in Message History

When fetching message history, if a member was added to a group the logged-in user is part of, the list will contain an [`Action`](https://www.cometchat.com/docs/sdk/reference/messages#action) message with these fields:

1. `action` - `added`
2. `actionOn` - [`User`](https://www.cometchat.com/docs/sdk/reference/entities#user) object containing the details of the user who was added to the group
3. `actionBy` - [`User`](https://www.cometchat.com/docs/sdk/reference/entities#user) object containing the details of the user who added the member to the group
4. `actionFor` - [`Group`](https://www.cometchat.com/docs/sdk/reference/entities#group) object containing the details of the group to which the member was added

> [!WARNING]
>
> Always remove group listeners when they're no longer needed (e.g., in `onDestroy()` or when navigating away). Failing to remove listeners can cause memory leaks and duplicate event handling.

## GroupMember Payload Structure

> [accordion] GroupMember Object
>
> The [`GroupMember`](https://www.cometchat.com/docs/sdk/reference/entities#groupmember) object extends [`User`](https://www.cometchat.com/docs/sdk/reference/entities#user) and contains all User fields plus group-specific fields:
>
> | Parameter | Type | Description |
> | - | - | - |
> | `uid` | String | Unique identifier of the user |
> | `name` | String | Display name of the user |
> | `avatar` | String | URL to user's profile picture |
> | `link` | String | URL to user's profile page |
> | `role` | String | User role for access control |
> | `metadata` | JSONObject | Custom data set by developer |
> | `status` | String | User online status. Values: `"online"`, `"offline"` |
> | `statusMessage` | String | Custom status message |
> | `lastActiveAt` | long | Unix timestamp of last activity |
> | `hasBlockedMe` | boolean | Whether this user has blocked the logged-in user |
> | `blockedByMe` | boolean | Whether the logged-in user has blocked this user |
> | `tags` | Array\<String> | List of tags for user identification |
> | `deactivatedAt` | long | Unix timestamp when user was deactivated (0 if active) |
> | `scope` | String | Member's scope in the group. Values: `"admin"`, `"moderator"`, `"participant"` |
> | `joinedAt` | long | Unix timestamp when member joined the group |
>
> **Sample GroupMember Object:**
>
> ```json theme={null}
> {
>   "uid": "user_123",
>   "name": "John Doe",
>   "avatar": "https://example.com/avatar.png",
>   "link": "https://example.com/profile",
>   "role": "default",
>   "metadata": {
>     "department": "Engineering",
>     "title": "Senior Developer"
>   },
>   "status": "online",
>   "statusMessage": "Available",
>   "lastActiveAt": 1699900000,
>   "hasBlockedMe": false,
>   "blockedByMe": false,
>   "tags": ["premium", "verified"],
>   "deactivatedAt": 0,
>   "scope": "admin",
>   "joinedAt": 1699850000
> }
> ```

***

## Next Steps

> [card] [Kick Member](https://www.cometchat.com/docs/sdk/android/v4/group-kick-member.md)
>
> Remove members from groups

> [card] [Change Member Scope](https://www.cometchat.com/docs/sdk/android/v4/group-change-member-scope.md)
>
> Update member roles and permissions

> [card] [Retrieve Members](https://www.cometchat.com/docs/sdk/android/v4/retrieve-group-members.md)
>
> Fetch list of group members

> [card] [Group Listeners](https://www.cometchat.com/docs/sdk/android/v4/real-time-listeners.md)
>
> Handle real-time group events


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.