---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/moderation
title: Moderate misbehaving users as a chat administrator
updated_at: 2026-06-15T12:12:02.878Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Moderate misbehaving users as a chat administrator

:::note
Enable [App Context](https://youtu.be/9UEoSlngpYI) in the [Admin Portal](https://admin.pubnub.com/) to work with user metadata.
:::

Administrators are chat users with SDK instances [initialized with SecretKey](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/configuration#additional-configuration-options). Admin moderation capabilities:

* Mute users on channels
* Ban users from accessing channels

Use [Access Manager](https://www.pubnub.com/docs/sdks/unity/api-reference/access-manager) to enforce restrictions. See also [moderation for regular users](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/moderation-user).

## Mute or ban users as an administrator

Mute or ban users with `SetRestriction()` or `SetRestrictions()` on the `Chat`, `User`, or `Channel` object. All three produce the same output with different input parameters.

**How it works:**

* Muting/banning creates a [moderation](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/custom-events#events-for-user-moderation) event (`muted` or `banned`)
* A moderation membership is created with `PUBNUB_INTERNAL_MODERATION_` prefix (filtered from [GetMemberships()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership#get-membership) results)
* Lifting restrictions removes the moderation membership and creates a `lifted` event

[Listen to moderation events](#listen-to-moderation-events) to trigger actions like removing [memberships](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/membership). [Check restrictions](#check-restrictions) to verify user status.

:::note Secret Key required
Initialize with **Secret Key** (from [Admin Portal](https://admin.pubnub.com/)) for admin operations. Never expose `SecretKey` to clients. If compromised, generate a new one in the Admin Portal.
:::

### Method signature

These methods take the following parameters:

* SetRestriction() (on the Chat object) 1chat.SetRestriction(2 string userId, 3 string channelId, 4 Restriction restriction5)
* SetRestriction() (on the User object) 1user.SetRestriction(2 string channelId,3 Restriction restriction4)
* SetRestrictions() (on the Channel object) 1channel.SetRestrictions(2 string userId,3 Restriction restriction4)

#### Input

| Parameter | Required for Chat | Required for User | Required for Channel | Description |
| --- | --- | --- | --- | --- |
| userId | string | Optional |  | Yes | No | Yes | [Unique User ID](https://www.pubnub.com/docs/general/setup/users-and-devices) that becomes your app's current user. It's a string of up to 92 characters that identifies a single client (end user, device, or server) that connects to PubNub. Based on User ID, PubNub calculates pricing for your apps' usage. User ID should be persisted and remain unchanged. If you don't set `userId`, you won't be able to connect to PubNub. In this method, `userId` stands for the user that you want to mute or ban. |
| channelId | string | Optional |  | Yes | Yes | No | ID of the channel on/from which the user should be muted or banned. |
| restriction | Restriction | Optional |  | Yes | Yes | Yes | Moderation restrictions and reasoning behind them. |
| > ban | boolean | Optional |  | No | No | No | Value that represents the user's moderation restrictions. Set to `true` to ban the user from the channel or to `false` to unban them. |
| > mute | boolean | Optional |  | No | No | No | Value that represents the user's moderation restrictions. Set to `true` to mute the user on the channel or to `false` to unmute them. |
| > reason | string | Optional |  | No | No | No | Reason why you want to ban or mute the user. |

#### Output

An awaitable `Task<ChatOperationResult>`.

### Sample code

#### Mute

Mute `support_agent_15` on the `support` channel.

* SetRestriction() (on the Chat object) using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } await chat.SetRestriction( userId: "support_agent_15", channelId: "support", restriction: new Restriction() { Ban = false, Mute = true, Reason = string.Empty } );
* SetRestriction() (on the User object) using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var userResult = await chat.GetUser("support_agent_15"); if (!userResult.Error) { var user = userResult.Result; await user.SetRestriction( "support", new Restriction() { Ban = false, Mute = true, Reason = string.Empty } ); }
* SetRestrictions() (on the Channel object) using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var channelResult = await chat.GetChannel("support"); if (!channelResult.Error) { var channel = channelResult.Result; await channel.SetRestrictions( "support_agent_15", new Restriction() { Ban = false, Mute = true, Reason = string.Empty } ); }

#### Ban

Ban `support_agent_15` from the `support` channel.

* SetRestriction() (on the Chat object) using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } await chat.SetRestriction( "support_agent_15", "support", new Restriction() { Ban = true, Mute = false, Reason = "Violated community guidelines" } );
* SetRestriction() (on the User object) using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var userResult = await chat.GetUser("support_agent_15"); if (!userResult.Error) { var user = userResult.Result; await user.SetRestriction( "support", new Restriction() { Ban = true, Mute = false, Reason = "Violated community guidelines" } ); }
* SetRestrictions() (on the Channel object) using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var channelResult = await chat.GetChannel("support"); if (!channelResult.Error) { var channel = channelResult.Result; await channel.SetRestrictions( "support_agent_15", new Restriction() { Ban = true, Mute = false, Reason = "Violated community guidelines" } ); }

## Check restrictions

### One user on one channel

Check if there are any `mute` or `ban` restrictions set for a user on one channel using the `GetChannelRestrictions()` and `GetUserRestrictions()` methods.

#### Method signature

These methods take the following parameters:

* GetChannelRestrictions() 1user.GetChannelRestrictions(Channel channel)
* GetUserRestrictions() 1channel.GetUserRestrictions(User user)

##### Input

| Parameter | Required in `GetChannelRestrictions()` | Required in `GetUserRestrictions()` | Description |
| --- | --- | --- | --- |
| `channel`Type: `Channel`Default: n/a | Yes | No | [Channel](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/channel) on/from which the user can be muted or banned. |
| `user`Type: `User`Default: n/a | No | Yes | [User](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/user) that can be muted or banned. |

##### Output

These methods return an awaitable `Task<ChatOperationResult<Restriction>>` object.

```csharp
 public class Restriction
    {
        public bool Ban;
        public bool Mute;
        public string Reason;
    }
```

#### Sample code

Check if the user `support_agent_15` has any restrictions set on the `support` channel.

* GetChannelRestrictions() using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var channelResult = await chat.GetChannel("support"); if (channelResult.Error) { Debug.Log("Couldn't find channel!"); return; } var channel = channelResult.Result; var userResult = await chat.GetUser("support_agent_15"); if (userResult.Error) { Debug.Log("Couldn't find user!"); return; } var user = userResult.Result; // check user restrictions var restrictionResult = await user.GetChannelRestrictions(channel); var restriction = restrictionResult.Result;
* GetUserRestrictions() using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } var channelResult = await chat.GetChannel("support"); if (channelResult.Error) { Debug.Log("Couldn't find channel!"); return; } var channel = channelResult.Result; var userResult = await chat.GetUser("support_agent_15"); if (userResult.Error) { Debug.Log("Couldn't find user!"); return; } var restrictedUser = userResult.Result; var restrictionResult = await channel.GetUserRestrictions(restrictedUser); var restriction = restrictionResult.Result;

### One user on all channels

Check if there are any `mute` or `ban` restrictions set for a user on all channels they are a member of using the `GetChannelsRestrictions()` method.

#### Method signature

This method takes the following parameters:

```csharp
user.GetChannelsRestrictions(
    string sort = "",
    int limit = 0,
    PNPageObject page = null
)
```

##### Input

| Parameter | Description |
| --- | --- |
| `sort`Type: `string`Default: empty string | Key-value pair of a property to sort by, and a sort direction. Available options are `id`, `name`, and `updated`. Use `asc` or `desc` to specify the sorting direction, or specify `null` to take the default sorting direction (ascending). For example: `{name: "asc"}`. By default, the items are sorted by the last updated date. |
| `limit`Type: `int`Default: `0` | Number of objects to return in response. |
| `page`Type: `PNPageObject`Default: `null` | Object used for pagination to define which previous or next result page you want to fetch. |

##### Output

| Type | Description |
| --- | --- |
| `Task<ChatOperationResult<ChannelsRestrictionsWrapper>>` | An awaitable `Task` with an object containing the filtered, sorted, and paginated list of user restrictions. |

#### Sample code

List all `mute` and `ban` restrictions set for the user `support_agent_15`.

```csharp
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var userResult = await chat.GetUser("support_agent_15");
if(userResult.Error){
    return;    
}
var user = userResult.Result;
var restrictionsWrapperResult = await user.GetChannelsRestrictions();
if (!restrictionsWrapperResult.Error)
{
    foreach(var restriction in restrictionsWrapperResult.Result.Restrictions)
    {
        Debug.Log($"Channel: {restriction.ChannelId}, Ban: {restriction.Ban}, Mute: {restriction.Mute}");
    }
}
```

### All users on one channel

Check if there are any `mute` or `ban` restrictions set for members of a given channel using the `GetUsersRestrictions()` method.

#### Method signature

This method takes the following parameters:

```csharp
channel.GetUsersRestrictions(
    string sort = "",
    int limit = 0,
    PNPageObject page = null
)
```

##### Input

| Parameter | Description |
| --- | --- |
| `sort`Type: `string`Default: empty string | Key-value pair of a property to sort by, and a sort direction. Available options are `id`, `name`, and `updated`. Use `asc` or `desc` to specify the sorting direction, or specify `null` to take the default sorting direction (ascending). For example: `{name: "asc"}`. By default, the items are sorted by the last updated date. |
| `limit`Type: `int`Default: `0` | Number of objects to return in response. |
| `page`Type: `PNPageObject`Default: `null` | Object used for pagination to define which previous or next result page you want to fetch. |

##### Output

| Type | Description |
| --- | --- |
| `Task<ChatOperationResult<UsersRestrictionsWrapper>>` | An awaitable `Task` with an object containing the filtered, sorted, and paginated list of restricted users. |

#### Sample code

List all `mute` and `ban` restrictions set for the `support` channel.

```csharp
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var channelResult = await chat.GetChannel("support");
if (channelResult.Error) return;
var channel = channelResult.Result;
        
var restrictionsWrapperResult = await channel.GetUsersRestrictions();
if (!restrictionsWrapperResult.Error)
{
    foreach(var userRestriction in restrictionsWrapperResult.Result.Restrictions)
    {
        Debug.Log(
                    $"User: {userRestriction.UserId}, " +
                    $"Banned: {userRestriction.Ban}, " +
                    $"Muted: {userRestriction.Mute}, " +
                    $"Reason: {userRestriction.Reason}");
    }
}
```

## Secure moderation

Client-side UI restrictions (hiding channels, disabling input) can be bypassed. Secure with [server-side logic](#server-side-restrictions) using Access Manager, plus optional [client-side feedback](#client-side-restrictions).

:::note
See [Moderation as user](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/moderation-user) for client-side moderation options.
:::

### Server-side restrictions

Use [Access Manager](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/permissions) with Chat SDK methods to grant/revoke permissions based on muting/banning restrictions.

:::warning Access Manager permissions
With `SyncMutedUsers` enabled, grant these permissions (replace `$currentUserId` with actual user ID):
* `read` on `PN_PRV.$currentUserId.mute1` channel
* `update`, `delete`, `get` on `PN_PRV.$currentUserId.mute1` user
:::

**Recommended workflow:**

1. Admin [sets restrictions](#mute-or-ban-users-as-an-administrator) via dashboard
2. [Get moderation restrictions](#check-restrictions) for users
3. Call Access Manager API to generate/revoke tokens

**Implementation steps:**

1. Enable Access Manager. Navigate to your app's keyset in the Admin Portal and turn on the ACCESS MANAGER option.
2. Initialize Unity Chat SDK with AuthKey. On the frontend of your app, initialize the Unity Chat SDK with the authentication key (AuthKey) on your clients. Use it for all requests made to PubNub APIs to authenticate users in your application and grant them access to PubNub resources (other users' metadata and channels).
3. Secure backend initialization. On the backend, initialize the Unity SDK with the secret key (SecretKey) on your servers to secure your PubNub instance. Secret keySecretKey is a secret shared between your application's server and PubNub and it's used to administer Access Manager permissions for your client applications by signing and verifying the authenticity of messages and requests. Remember to never expose the SecretKey to client devices.
4. Get user permissions. Retrieve detailed user restrictions and convert these details into a simplified permission format where each channel is marked with whether the user can read, write, or access it, based on such restrictions as bans or mutes using the Get user details and Check restrictions methods.
5. Generate authorization token. Using the Unity SDK, generate and assign an access token reflecting the user's permissions. The token contains information about which channels the user can access and how (read/write), and it's configured with a specific validity period. This token serves as a key for users to interact with the application according to their permissions. Operation-to-permission mappingRead the Permissions document for a complete list of available operations that users can do with PubNub resources in apps created with the Unity Chat SDK. Set short TTLsYou can mute or ban a user for an indefinite amount of time, but you can unmute/unban them at any time. To make sure that the permissions set with Access Manager reflect the most up-to-date muting/banning restrictions on the client-side, it's recommended to set short-lived tokens (TTLs) for grant calls (valid for seconds and minutes rather than hours or days). Alternatively, if new muting/banning restrictions are set on the frontend side of your app, you can revoke Access Manager permissions on the backend using the chat.sdk.RevokeToken() method.
6. Listen for moderation events. Set up a listener to listen for the moderation event type ("banned," "muted," or "lifted") generated when UI restrictions are added or removed.
7. Act on moderation events. Update permissions in response to moderation events and generate new tokens if necessary.

### Client-side restrictions

With [server-side permissions](#server-side-restrictions) enforced, add optional client-side UI feedback.

:::note
See [Client-side restrictions](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/moderation-user#client-side-restrictions) for regular user moderation.
:::

## Listen to moderation events

`StreamModerationEvents()` sends notifications when users are muted/banned or removes memberships on ban. Use `OnRestrictionChanged` to handle updates.

:::tip Events documentation
To read more about the events of type `Moderation`, refer to the [Chat events](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/custom-events#events-for-user-moderation) documentation.
:::

:::tip Method naming
Earlier versions used `SetListeningForModerationEvents()` to enable streaming. This method has been superseded by `StreamModerationEvents()`, though it remains available for backward compatibility.
:::

### Method signature

These methods take the following parameters:

* StreamModerationEvents() 1user.StreamModerationEvents(bool stream)
* OnRestrictionChanged - Event signature 1// event on the User entity — enabled by StreamModerationEvents()2public event Action<ChannelRestriction> OnRestrictionChanged;3// needs a corresponding event handler4void EventHandler(ChannelRestriction restriction)

#### Input

| Parameter | Required in `StreamModerationEvents()` | Required in `OnRestrictionChanged` | Description |
| --- | --- | --- | --- |
| `stream`Type: `bool`Default: n/a | Yes | n/a | Whether to start (`true`) or stop (`false`) listening to moderation events for the user. Events are received from the user's channel (automatically prefixed with `PUBNUB_INTERNAL_MODERATION.`). |
| `restriction`Type: `ChannelRestriction`Default: n/a | No | Yes | Typed moderation data containing information about the restriction change (ban, mute, or lifted). |

#### Output

These methods don't return a value. Moderation event updates are delivered through the `OnRestrictionChanged` event handler.

### Sample code

Send a `Moderation` event to the muted user.

```csharp
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var userResult = await chat.GetUser("support_agent_15");
if(userResult.Error){
    Debug.Log("Couldn't find user!");
    return;
}
var user = userResult.Result;

user.StreamModerationEvents(true);

user.OnRestrictionChanged += OnModerationEventHandler; // or use lambda

void OnModerationEventHandler(ChannelRestriction restriction)
{
    Debug.Log($"New restriction status for {restriction.ChannelId} received, " +
              $"ban: {restriction.Ban}, mute: {restriction.Mute}, reason: {restriction.Reason}");
}
```