> ## 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.

# Community Moderation

> Assign roles, ban or unban members, and check community permissions

Use community moderation APIs for role assignment, ban management, and permission checks. Role IDs must already exist in your network; these APIs assign or remove roles from users, but they do not create roles.

## Parameters

| Operation            | Parameter           | Required | Description                                                        |
| -------------------- | ------------------- | -------- | ------------------------------------------------------------------ |
| Add roles            | `communityId`       | Yes      | Community ID where roles should be assigned.                       |
| Add roles            | `roleIds` / `roles` | Yes      | Existing role IDs to assign. Flutter accepts one role ID per call. |
| Add roles            | `userIds`           | Yes      | User IDs that should receive the roles.                            |
| Remove roles         | `communityId`       | Yes      | Community ID where roles should be removed.                        |
| Remove roles         | `roleIds` / `roles` | Yes      | Existing role IDs to remove. Flutter accepts one role ID per call. |
| Remove roles         | `userIds`           | Yes      | User IDs whose roles should be updated.                            |
| Ban or unban members | `communityId`       | Yes      | Community ID whose ban list should change.                         |
| Ban or unban members | `userIds`           | Yes      | User IDs to ban or unban.                                          |
| Check permissions    | `permission`        | Yes      | Permission value to check, such as ban-community-user.             |
| Check permissions    | `communityId`       | Yes      | Community where the permission should be evaluated.                |

## Role Management

TypeScript, iOS, and Android accept a list of role IDs. Flutter exposes `addRole()` and `removeRole()` for one role ID per call.

### Add Roles

Add role IDs to one or more users after the roles already exist in your network.

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

  do {
      try await communityModeration.addRoles(
          ["community-moderator"],
          userIds: ["user1", "user2"]
      )
  } catch let error {
      handleError(error)
  }
  ```

  ```kotlin Android theme={null}
  fun addRoles(communityRepository: AmityCommunityRepository) {
      communityRepository
          .moderation(communityId = "communityId")
          .addRoles(
              roles = listOf("community-moderator"),
              userIds = listOf("user1", "user2")
          )
          .doOnComplete {
              // Roles added
          }
          .subscribe()
  }
  ```

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

  async function addRoles(
    communityId: Amity.Community['communityId'],
    roleIds: Amity.Role['roleId'][],
    userIds: Amity.User['userId'][],
  ): Promise<boolean> {
    return CommunityRepository.Moderation.addRoles(communityId, roleIds, userIds);
  }
  ```

  ```dart Flutter theme={null}
  Future<void> addRole(String communityId, List<String> userIds) async {
    await AmitySocialClient.newCommunityRepository()
        .moderation(communityId)
        .addRole('community-moderator', userIds);
  }
  ```
</CodeGroup>

### Remove Roles

Remove role IDs from one or more users when they should no longer have that community role.

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

  do {
      try await communityModeration.removeRoles(
          ["community-moderator"],
          userIds: ["user1", "user2"]
      )
  } catch let error {
      handleError(error)
  }
  ```

  ```kotlin Android theme={null}
  fun removeRoles(communityRepository: AmityCommunityRepository) {
      communityRepository
          .moderation(communityId = "communityId")
          .removeRoles(
              roles = listOf("community-moderator"),
              userIds = listOf("user1", "user2")
          )
          .doOnComplete {
              // Roles removed
          }
          .subscribe()
  }
  ```

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

  async function removeRoles(
    communityId: Amity.Community['communityId'],
    roleIds: Amity.Role['roleId'][],
    userIds: Amity.User['userId'][],
  ): Promise<boolean> {
    return CommunityRepository.Moderation.removeRoles(communityId, roleIds, userIds);
  }
  ```

  ```dart Flutter theme={null}
  Future<void> removeRole(String communityId, List<String> userIds) async {
    await AmitySocialClient.newCommunityRepository()
        .moderation(communityId)
        .removeRole('community-moderator', userIds);
  }
  ```
</CodeGroup>

## Ban Members

Use `banMembers()` / `banMember()` to ban users from a community.

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

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

  ```kotlin Android theme={null}
  fun banMembers(communityRepository: AmityCommunityRepository) {
      communityRepository
          .moderation(communityId = "communityId")
          .banMembers(userIds = listOf("user1", "user2"))
          .doOnComplete {
              // Members banned
          }
          .subscribe()
  }
  ```

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

  async function banMembers(
    communityId: Amity.Community['communityId'],
    userIds: Amity.User['userId'][],
  ) {
    const { data: bannedMembers } =
      await CommunityRepository.Moderation.banMembers(communityId, userIds);

    return bannedMembers;
  }
  ```

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

## Unban Members

Use `unbanMembers()` / `unbanMember()` to remove community bans.

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

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

  ```kotlin Android theme={null}
  fun unbanMembers(communityRepository: AmityCommunityRepository) {
      communityRepository
          .moderation(communityId = "communityId")
          .unbanMembers(userIds = listOf("user1", "user2"))
          .doOnComplete {
              // Members unbanned
          }
          .subscribe()
  }
  ```

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

  async function unbanMembers(
    communityId: Amity.Community['communityId'],
    userIds: Amity.User['userId'][],
  ) {
    const { data: unbannedMembers } =
      await CommunityRepository.Moderation.unbanMembers(communityId, userIds);

    return unbannedMembers;
  }
  ```

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

## Check Permissions

Permission checks use the current user's cached permission state. Query the relevant community/member state before relying on the result for UI decisions.

<CodeGroup>
  ```swift iOS theme={null}
  let canBan = await client.hasPermission(
      .banCommunityUser,
      forCommunity: communityId
  )
  ```

  ```kotlin Android theme={null}
  fun checkCommunityPermission() {
      AmityCoreClient
          .hasPermission(permission = AmityPermission.BAN_COMMUNITY_USER)
          .atCommunity(communityId = "communityId")
          .check()
          .doOnNext { hasPermission: Boolean ->
              // Render permission-aware UI
          }
          .subscribe()
  }
  ```

  ```typescript TypeScript theme={null}
  function checkCommunityPermission(communityId: Amity.Community['communityId']) {
    return client
      .hasPermission(Amity.Permission.BanChannelCommunityPermission)
      .community(communityId);
  }
  ```

  ```dart Flutter theme={null}
  void checkCommunityPermission(String communityId) {
    final hasPermission = AmityCoreClient
        .hasPermission(AmityPermission.BAN_COMMUNITY_USER)
        .atCommunity(communityId)
        .check();
  }
  ```
</CodeGroup>

## Related Topics

<CardGroup cols={2}>
  <Card title="Member Management" href="./member-management" icon="users">
    Add and remove community members
  </Card>

  <Card title="Join / Leave Community" href="./join-leave-community" icon="arrows-right-left">
    User-initiated joining, leaving, and approval workflows
  </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>
