On this page

Report misbehaving users

Requires App Context

Enable App Context in the Admin Portal to work with user metadata.

Administrators are chat users with SDK instances initialized with a Secret Key. Admin moderation capabilities:

  • Mute users on channels
  • Ban users from accessing channels

Use Access Manager to enforce restrictions.

icon

Usage in Blueprints and C++


Mute or ban users

Mute or ban users with 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 event (muted or banned)
  • A moderation membership is created with PUBNUB_INTERNAL_MODERATION_ prefix (secured via Access Manager, filtered from GetMemberships() results)
  • Lifting restrictions removes the moderation membership and creates a lifted event

Listen to moderation events to trigger actions like removing memberships. Check restrictions to verify user status.

Secret Key required

Initialize with Secret Key (from Admin Portal) for admin operations. Never expose Secret Key to clients. If compromised, generate a new one in the Admin Portal.

Method signature

Output

These methods don't return any value.

Sample code

Mute

Mute support_agent_15 on the support channel.

  • SetRestrictions() (on the Chat object)

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Define user ID
    10FString UserID = "support_agent_15";
    11
    12FString ChannelID = "support";
    13
    14FPubnubRestriction Restrictions;
    15Restrictions.Mute = true;
    show all 20 lines
  • SetRestrictions() (on the User object)

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Define user ID
    10FString UserID = "support_agent_15";
    11FString ChannelID = "support";
    12
    13// Get the user and save the reference
    14UPubnubUser* User = Chat->GetUser(UserID);
    15
    show all 22 lines
  • SetRestrictions() (on the Channel object)

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Define user ID
    10FString UserID = "support_agent_15";
    11FString ChannelID = "support";
    12
    13// Get the user and save the reference
    14UPubnubChannel* Channel = Chat->GetChannel(ChannelID);
    15
    show all 22 lines

Ban

Ban support_agent_15 from the support channel.

  • SetRestrictions() (on the Chat object)

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Define user ID
    10FString UserID = "support_agent_15";
    11
    12FString ChannelID = "support";
    13
    14FPubnubRestriction Restrictions;
    15Restrictions.Mute = false;
    show all 20 lines
  • SetRestrictions() (on the User object)

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Define user ID
    10FString UserID = "support_agent_15";
    11FString ChannelID = "support";
    12
    13// Get the user and save the reference
    14UPubnubUser* User = Chat->GetUser(UserID);
    15
    show all 22 lines
  • SetRestrictions() (on the Channel object)

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Define user ID
    10FString UserID = "support_agent_15";
    11FString ChannelID = "support";
    12
    13// Get the user and save the reference
    14UPubnubChannel* Channel = Chat->GetChannel(ChannelID);
    15
    show all 22 lines

Check restrictions

One user on one channel

Check mute or ban restrictions for a user on a specific channel with GetChannelRestrictions() or GetUserRestrictions().

Method signature

Output
ParameterDescription
FPubnubRestriction
Type: struct
Returned object containing three fields: Ban, Mute, and Reason.
 → Ban
Type: bool
Info whether the user is banned from the channel.
 → Mute
Type: bool
Info whether the user is muted on the channel.
 → Reason
Type: FString
Reason why the user was banned or muted.

Sample code

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

  • GetChannelRestrictions()

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Define user ID
    10FString UserID = "support_agent_15";
    11
    12// Get the user and save the reference
    13UPubnubUser* User = Chat->GetUser(UserID);
    14UPubnubChannel* Channel = Chat->GetChannel("support");
    15
    show all 16 lines
  • GetUserRestrictions()

    1#include "Kismet/GameplayStatics.h"
    2#include "PubnubChatSubsystem.h"
    3
    4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
    5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
    6
    7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
    8
    9// Define user ID
    10FString UserID = "support_agent_15";
    11
    12// Get the user and save the reference
    13UPubnubUser* User = Chat->GetUser(UserID);
    14UPubnubChannel* Channel = Chat->GetChannel("support");
    15
    show all 16 lines

One user on all channels

Check mute or ban restrictions for a user across all their channels with GetChannelsRestrictions().

Method signature

Output
ParameterDescription
FPubnubChannelsRestrictionsWrapper
Type: struct
Returned object containing these fields: Page, Total, Status, and Restrictions.
 → page
Type: object
Object used for pagination to define which previous or next result page you want to fetch.
   → Next
Type: FString
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   → Prev
Type: FString
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.
 → Total
Type: int
Total number of restrictions.
 → Status
Type: int
Status code of a server response, like 200.
 → Restrictions
Type: TArray<FPubnubChannelRestriction>
Array containing restrictions.
   → Ban
Type: bool
Info whether the user is banned from the given channel.
   → Mute
Type: bool
Info whether the user is muted on the given channel.
   → Reason
Type: FString
Reason why the user was banned or muted.
   → Channel ID
Type: FString
ID of the channel containing user restrictions.

Sample code

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

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Define user ID
10FString UserID = "support_agent_15";
11
12// Get the user and save the reference
13UPubnubUser* User = Chat->GetUser(UserID);
14
15FPubnubChannelsRestrictionsWrapper Restrictions = User->GetChannelsRestrictions();

All users on one channel

Check mute or ban restrictions for all members of a channel with GetUsersRestrictions().

Method signature

Output
ParameterDescription
FPubnubUsersRestrictionsWrapper
Type: struct
Returned object containing these fields: Page, Total, Status, and Restrictions.
 → page
Type: object
Object used for pagination to define which previous or next result page you want to fetch.
   → Next
Type: FString
Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   → Prev
Type: FString
Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.
 → Total
Type: int
Total number of restrictions.
 → Status
Type: int
Status code of a server response, like 200.
 → Restrictions
Type: TArray<FPubnubUserRestriction>
Array containing restrictions.
   → Ban
Type: bool
Info whether the user is banned from the given channel.
   → Mute
Type: bool
Info whether the user is muted on the given channel.
   → Reason
Type: FString
Reason why the user was banned or muted.
   → User ID
Type: FString
ID of the restricted user.

Sample code

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

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FPubnubUsersRestrictionsWrapper Restrictions = Channel->GetUsersRestrictions();

Secure moderation

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

Server-side restrictions

Use Access Manager with Chat SDK methods to grant/revoke permissions based on muting/banning restrictions.

Recommended workflow:

  1. Admin sets restrictions via dashboard (e.g., Channel Monitor)
  2. Get moderation restrictions for users
  3. Call Access Manager API to generate/revoke tokens

Implementation steps:

  1. Enable Access Manager in the Admin Portal.

  2. Initialize Chat SDK with Auth Key on the frontend to authenticate users and grant access to PubNub resources.

  3. Initialize backend with Secret Key using the Unreal SDK to secure your PubNub instance.

    tip

    Secret Key signs and verifies messages for Access Manager. Never expose to clients.

  4. Get user permissions - Retrieve restrictions with Get user details and Check restrictions, then convert to permission format (read/write/access per channel).

  5. Generate authorization token - Assign an access token with channel permissions and validity period.

    tip

    See Permissions for the complete operation-to-permission mapping.

    Short TTLs recommended

    Use short-lived tokens (TTLs) for up-to-date restrictions.

  6. Listen for moderation events - Listen for the moderation event type (banned, muted, or lifted).

  7. Act on moderation events - Update permissions and generate new tokens as needed.

Client-side restrictions

With server-side permissions enforced, add optional client-side UI feedback. Read moderation restrictions to display popup messages or icons informing users about their mute/ban status before they attempt restricted actions.

Listen to moderation events

ListenForEvents() sends notifications when users are muted/banned or removes memberships on ban.

Events documentation

See Chat events for moderation event details.

Method signature

icon

Handle the response

Output

This method doesn't return any value.

Sample code

Listen for moderation events on the user123 channel.

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");
8
9FString UserID = "user123";
10FString ChannelID = "PUBNUB_INTERNAL_MODERATION." + UserID;
11
12// Create a pubnub response delegate
13// you MUST implement your own callback function to handle the response
14FOnPubnubEventReceived ListenResponse;
15ListenResponse.BindDynamic(this, &AMyActor::OnListenResponseReceived);
show all 21 lines
Last updated on