> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Member Management

> Add and remove community members with the community membership APIs

Use member management APIs when a moderator or admin needs to add users to a community or remove existing members. These APIs are separate from user-initiated join and leave flows.

<Info>
  Member management APIs require the current user to have the relevant community permissions. The SDK methods perform the operation; your app should query member lists afterward if the UI needs an updated collection.
</Info>

## Parameters

| Operation      | Parameter     | Required | Description                                  |
| -------------- | ------------- | -------- | -------------------------------------------- |
| Add members    | `communityId` | Yes      | Community ID whose membership should change. |
| Add members    | `userIds`     | Yes      | User IDs to add to the community.            |
| Remove members | `communityId` | Yes      | Community ID whose membership should change. |
| Remove members | `userIds`     | Yes      | User IDs to remove from the community.       |

## Add Members

Use `addMembers()` to add one or more users to a community.

<CodeGroup>
  ```swift iOS theme={null}
  let communityMembership = AmityCommunityMembership(communityId: communityId)

  do {
      try await communityMembership.addMembers(["user1", "user2"])
  } catch let error {
      handleError(error)
  }
  ```

  ```kotlin Android theme={null}
  fun addMembers(communityRepository: AmityCommunityRepository) {
      communityRepository
          .membership(communityId = "communityId")
          .addMembers(userIds = listOf("user1", "user2"))
          .doOnComplete {
              // Members added
          }
          .doOnError { throwable ->
              // Handle error
          }
          .subscribe()
  }
  ```

  ```typescript TypeScript theme={null}
  import { CommunityRepository } from '@amityco/ts-sdk';

  async function addMembers(
    communityId: Amity.Community['communityId'],
    userIds: Amity.User['userId'][],
  ): Promise<boolean> {
    return CommunityRepository.Membership.addMembers(communityId, userIds);
  }
  ```

  ```dart Flutter theme={null}
  Future<void> addMembers(String communityId, List<String> userIds) async {
    await AmitySocialClient.newCommunityRepository()
        .membership(communityId)
        .addMembers(userIds);
  }
  ```
</CodeGroup>

## Remove Members

Use `removeMembers()` to remove one or more users from a community.

<Warning>
  Removing members changes their community membership immediately. If the community requires approval, removed users may need to request access again before rejoining.
</Warning>

<CodeGroup>
  ```swift iOS theme={null}
  let communityMembership = AmityCommunityMembership(communityId: communityId)

  do {
      try await communityMembership.removeMembers(["user1", "user2"])
  } catch let error {
      handleError(error)
  }
  ```

  ```kotlin Android theme={null}
  fun removeMembers(communityRepository: AmityCommunityRepository) {
      communityRepository
          .membership(communityId = "communityId")
          .removeMembers(userIds = listOf("user1", "user2"))
          .doOnComplete {
              // Members removed
          }
          .doOnError { throwable ->
              // Handle error
          }
          .subscribe()
  }
  ```

  ```typescript TypeScript theme={null}
  import { CommunityRepository } from '@amityco/ts-sdk';

  async function removeMembers(
    communityId: Amity.Community['communityId'],
    userIds: Amity.User['userId'][],
  ): Promise<boolean> {
    return CommunityRepository.Membership.removeMembers(communityId, userIds);
  }
  ```

  ```dart Flutter theme={null}
  Future<void> removeMembers(String communityId, List<String> userIds) async {
    await AmitySocialClient.newCommunityRepository()
        .membership(communityId)
        .removeMembers(userIds);
  }
  ```
</CodeGroup>

## Related Topics

<CardGroup cols={2}>
  <Card title="Community Moderation" href="./community-moderation" icon="shield-check">
    Assign roles and ban or unban community members
  </Card>

  <Card title="Join / Leave Community" href="./join-leave-community" icon="arrows-right-left">
    User-initiated membership workflows and approval requests
  </Card>

  <Card title="Query Community Members" href="./query-community-members" icon="magnifying-glass">
    Search and filter community member lists
  </Card>

  <Card title="Community Invitation" href="./community-invitation" icon="inbox-out">
    Invitation-based member onboarding workflows
  </Card>
</CardGroup>
