> ## Documentation Index
> Fetch the complete documentation index at: /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.

```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);
}
```

### Remove Roles

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

```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);
}
```

## Ban Members

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

```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);
}
```

## Unban Members

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

```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);
}
```

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

```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();
}
```

## Related Topics

> [card] [Member Management](/social-plus-sdk/social/communities-spaces/organization/member-management.md)
>
> Add and remove community members

> [card] [Join / Leave Community](/social-plus-sdk/social/communities-spaces/organization/join-leave-community.md)
>
> User-initiated joining, leaving, and approval workflows

> [card] [Query Community Members](/social-plus-sdk/social/communities-spaces/organization/query-community-members.md)
>
> Search and filter community member lists

> [card] [Community Invitation](/social-plus-sdk/social/communities-spaces/organization/community-invitation.md)
>
> Invitation-based member onboarding workflows


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