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++


Asynchronous and synchronous method execution

Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.

  • Asynchronous methods (Async suffix) return void and take an optional delegate parameter that fires when the operation completes.

    1Channel->SetRestrictionsAsync(UserID, Ban, Mute, OnOperationResponseDelegate, Reason);

    You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatOperationResponseNative).

  • Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.

    1FPubnubChatOperationResult Result = Channel->SetRestrictions(UserID, Ban, Mute, Reason);

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​

  • User->SetRestrictions()

    1User->SetRestrictions(
    2 const FString ChannelID,
    3 bool Ban,
    4 bool Mute,
    5 FString Reason = ""
    6);
  • Channel->SetRestrictions()

    1Channel->SetRestrictions(
    2 const FString UserID,
    3 bool Ban,
    4 bool Mute,
    5 FString Reason = ""
    6);
  • Chat->SetRestrictions()

    1Chat->SetRestrictions(FPubnubChatRestriction Restriction);
Restriction#
Default: no default
Struct containing UserID, ChannelID, Ban, Mute, and Reason fields. Used by Chat only.
Required for Chat
Yes
Required for User
No
Required for Channel
No
ChannelID#
Type: FString
Default: no default
ID of the channel on/from which the user should be muted or banned. Used by User and Channel.
Required for Chat
No
Required for User
Yes
Required for Channel
No
UserID#
Type: FString
Default: no default
Unique User ID of the user to mute or ban. Used by Channel only.
Required for Chat
No
Required for User
No
Required for Channel
Yes
Ban#
Type: bool
Default: no default
Set to true to ban the user from the channel or to false to unban them.
Required for Chat
No
Required for User
Yes
Required for Channel
Yes
Mute#
Type: bool
Default: no default
Set to true to mute the user on the channel or to false to unmute them.
Required for Chat
No
Required for User
Yes
Required for Channel
Yes
Reason#
Type: FString
Default: ""
Reason why you want to ban or mute the user.
Required for Chat
No
Required for User
No
Required for Channel
No

Output​

MethodReturn type
User->SetRestrictions()FPubnubChatOperationResult
Chat->SetRestrictions()FPubnubChatOperationResult
Channel->SetRestrictions()FPubnubChatOperationResult

Sample code​

Mute​

Mute support_agent_15 on the support channel.

  • SetRestrictions() (on the Chat object)

    1UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|Chat|Moderation")
    2void SetRestrictionsSample();
    3
    4UFUNCTION()
    5void OnSetRestrictionsResponse(const FPubnubChatOperationResult& Result);
    6
    1
    
    2// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
    3void ASample_Chat::SetRestrictionsSample()
    4{
    5
    6 // Assumes Chat is a valid and initialized instance of UPubnubChat
    7
    8 // Set or lift moderation restrictions (e.g. ban or mute a user on a channel)
    9 FPubnubChatRestriction Restriction;
    10 Restriction.UserID = TEXT("Player_002");
    11 Restriction.ChannelID = TEXT("Lobby_001");
    12 Restriction.Ban = true;
    13 Restriction.Reason = TEXT("Violation of rules");
    14
    15 FOnPubnubChatOperationResponseNative Callback;
    show all 26 lines
  • SetRestrictions() (on the User object)

    1
    
    2// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
    3void ASample_ChatUser::SetRestrictionsSample()
    4{
    5
    6 // Assumes User is a valid UPubnubChatUser (e.g. from GetUser)
    7
    8 // Channel ID on which to set or lift restrictions for this user
    9 FString ChannelID = TEXT("lobby-01");
    10
    11 // Set or lift ban/mute for this user on the channel
    12 User->SetRestrictionsAsync(ChannelID, false, true, nullptr, "inappropriate language");
    13}
  • SetRestrictions() (on the Channel object)

    1
    
    2// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
    3void ASample_ChatChannel::SetRestrictionsSample()
    4{
    5
    6 // Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)
    7
    8 // User ID to set restrictions for
    9 FString UserID = TEXT("user-abc123");
    10
    11 // Set restriction (ban in this example)
    12 Channel->SetRestrictionsAsync(UserID, true, false, nullptr, TEXT("Cheater"));
    13}

Ban​

Ban support_agent_15 from the support channel.

  • SetRestrictions() (on the Chat object)

    1UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|Chat|Moderation")
    2void SetRestrictionsSample();
    3
    4UFUNCTION()
    5void OnSetRestrictionsResponse(const FPubnubChatOperationResult& Result);
    6
    1
    
    2// ACTION REQUIRED: Replace ASample_Chat with name of your Actor class
    3void ASample_Chat::SetRestrictionsSample()
    4{
    5
    6 // Assumes Chat is a valid and initialized instance of UPubnubChat
    7
    8 // Set or lift moderation restrictions (e.g. ban or mute a user on a channel)
    9 FPubnubChatRestriction Restriction;
    10 Restriction.UserID = TEXT("Player_002");
    11 Restriction.ChannelID = TEXT("Lobby_001");
    12 Restriction.Ban = true;
    13 Restriction.Reason = TEXT("Violation of rules");
    14
    15 FOnPubnubChatOperationResponseNative Callback;
    show all 26 lines
  • SetRestrictions() (on the User object — ban example)

    1User->SetRestrictionsAsync("support", true, false, nullptr, "Banned for sending pictures of pineapple pizza.");
  • SetRestrictions() (on the Channel object)

    1
    
    2// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
    3void ASample_ChatChannel::SetRestrictionsSample()
    4{
    5
    6 // Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)
    7
    8 // User ID to set restrictions for
    9 FString UserID = TEXT("user-abc123");
    10
    11 // Set restriction (ban in this example)
    12 Channel->SetRestrictionsAsync(UserID, true, false, nullptr, TEXT("Cheater"));
    13}

Lift restrictions​

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​

  • User->GetChannelRestrictions()

    1User->GetChannelRestrictions(UPubnubChatChannel* Channel)
  • Channel->GetUserRestrictions()

    1Channel->GetUserRestrictions(UPubnubChatUser* User);
Channel#
Type: UPubnubChatChannel*
Default: no default
Channel object on/from which the user can be muted or banned.
Required in User->GetChannelRestrictions()
Yes
Required in Channel->GetUserRestrictions()
No
User#
Type: UPubnubChatUser*
Default: no default
User object that can be muted or banned.
Required in User->GetChannelRestrictions()
No
Required in Channel->GetUserRestrictions()
Yes
Output​
User->GetChannelRestrictions()#
Type: FPubnubChatGetRestrictionResult
Returned object containing Result and Restriction.
Channel->GetUserRestrictions()#
Type: FPubnubChatGetRestrictionResult
Returned object containing Result and Restriction.
property of Channel->GetUserRestrictions(): Result#
Type: FPubnubChatOperationResult
Operation status.
property of Channel->GetUserRestrictions(): Restriction#
Type: FPubnubChatRestriction
Restriction details.
property of Restriction: UserID#
Type: FString
ID of the restricted user.
property of Restriction: ChannelID#
Type: FString
ID of the channel.
property of Restriction: Ban#
Type: bool
Info whether the user is banned from the channel.
property of Restriction: Mute#
Type: bool
Info whether the user is muted on the channel.
property of Restriction: 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
    
    2// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
    3void ASample_ChatUser::GetChannelRestrictionsSample()
    4{
    5
    6 // Assumes User is a valid UPubnubChatUser (e.g. from GetUser)
    7
    8 // Channel to query restrictions for
    9 UPubnubChatChannel* Channel = nullptr;
    10
    11 // Callback for when the operation completes (returns ban/mute/reason)
    12 FOnPubnubChatGetRestrictionResponseNative Callback;
    13 // ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
    14 Callback.BindUObject(this, &ASample_ChatUser::OnGetChannelRestrictionsResponse);
    15 User->GetChannelRestrictionsAsync(Channel, Callback);
    show all 23 lines
  • GetUserRestrictions()

    1
    
    2// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
    3void ASample_ChatChannel::GetUserRestrictionsSample()
    4{
    5
    6 // Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)
    7
    8 // User to query restrictions for (e.g. from GetUser or members list)
    9 UPubnubChatUser* User = nullptr;
    10
    11 // Callback for when the operation completes (returns ban/mute/reason for this user)
    12 FOnPubnubChatGetRestrictionResponseNative Callback;
    13 // ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
    14 Callback.BindUObject(this, &ASample_ChatChannel::OnGetUserRestrictionsResponse);
    15 Channel->GetUserRestrictionsAsync(User, Callback);
    show all 23 lines

One user on all channels​

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

Method signature​

1User->GetChannelsRestrictions(
2 int Limit = 0,
3 FPubnubMembershipSort Sort = FPubnubMembershipSort(),
4 FPubnubPage Page = FPubnubPage()
5);
Limit#
Type: int
Default: 100
Number of objects to return in response. The default (and maximum) value is 100.
Page#
Type: FPubnubPage
Default: no default
Object used for pagination to define which previous or next result page you want to fetch.
property of Page: Next#
Type: FString
Default: no default
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.
property of Page: Prev#
Type: FString
Default: no default
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.
Sort#
Type: FPubnubMembershipSort
Default: no default
Struct used to specify a property to sort by and sort direction. Available options are id, name, and updated. Use asc or desc to specify the sorting direction. By default, the items are sorted by the last updated date.
Output​
FPubnubChatGetRestrictionsResult#
Type: struct
Returned object containing these fields: Result, Restrictions, Page, and Total.
property of FPubnubChatGetRestrictionsResult: Result#
Type: FPubnubChatOperationResult
Operation status.
property of FPubnubChatGetRestrictionsResult: Restrictions#
Type: TArray<FPubnubChatRestriction>
Array containing restrictions.
property of Restrictions: UserID#
Type: FString
ID of the restricted user.
property of Restrictions: ChannelID#
Type: FString
ID of the channel containing user restrictions.
property of Restrictions: Ban#
Type: bool
Info whether the user is banned from the given channel.
property of Restrictions: Mute#
Type: bool
Info whether the user is muted on the given channel.
property of Restrictions: Reason#
Type: FString
Reason why the user was banned or muted.
property of FPubnubChatGetRestrictionsResult: Page#
Type: FPubnubPage
Object used for pagination to define which previous or next result page you want to fetch.
property of Page: 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.
property of Page: 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.
property of FPubnubChatGetRestrictionsResult: Total#
Type: int
Total number of restrictions.

Sample code​

List all mute and ban restrictions set for a user.

1

2// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
3void ASample_ChatUser::GetChannelsRestrictionsSample()
4{
5
6 // Assumes User is a valid UPubnubChatUser (e.g. from GetUser)
7
8 // Callback for when the operation completes (returns restrictions across channels)
9 FOnPubnubChatGetRestrictionsResponseNative Callback;
10 // ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
11 Callback.BindUObject(this, &ASample_ChatUser::OnGetChannelsRestrictionsResponse);
12 User->GetChannelsRestrictionsAsync(Callback);
13}
14
15// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
show all 20 lines

All users on one channel​

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

Method signature​

1Channel->GetUsersRestrictions(
2 int Limit = 0,
3 FPubnubMembershipSort Sort = FPubnubMembershipSort(),
4 FPubnubPage Page = FPubnubPage()
5);
Limit#
Type: int
Default: 0 (server default)
Number of objects to return in response.
Page#
Type: FPubnubPage
Default: no default
Object used for pagination to define which previous or next result page you want to fetch.
property of Page: Next#
Type: FString
Default: no default
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.
property of Page: Prev#
Type: FString
Default: no default
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.
Sort#
Type: FPubnubMembershipSort
Default: no default
Struct used to specify a property to sort by and sort direction. Available options are id, name, and updated. Use asc or desc to specify the sorting direction. By default, the items are sorted by the last updated date.
Output​
FPubnubChatGetRestrictionsResult#
Type: struct
Returned object containing these fields: Result, Restrictions, Page, and Total.
property of FPubnubChatGetRestrictionsResult: Result#
Type: FPubnubChatOperationResult
Operation status.
property of FPubnubChatGetRestrictionsResult: Restrictions#
Type: TArray<FPubnubChatRestriction>
Array containing restrictions.
property of Restrictions: UserID#
Type: FString
ID of the restricted user.
property of Restrictions: ChannelID#
Type: FString
ID of the channel.
property of Restrictions: Ban#
Type: bool
Info whether the user is banned from the given channel.
property of Restrictions: Mute#
Type: bool
Info whether the user is muted on the given channel.
property of Restrictions: Reason#
Type: FString
Reason why the user was banned or muted.
property of FPubnubChatGetRestrictionsResult: Page#
Type: FPubnubPage
Object used for pagination to define which previous or next result page you want to fetch.
property of Page: 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.
property of Page: 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.
property of FPubnubChatGetRestrictionsResult: Total#
Type: int
Total number of restrictions.

Sample code​

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

1

2// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
3void ASample_ChatChannel::GetUsersRestrictionsSample()
4{
5
6 // Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)
7
8 // Callback for when the operation completes (returns list of restrictions)
9 FOnPubnubChatGetRestrictionsResponseNative Callback;
10 // ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
11 Callback.BindUObject(this, &ASample_ChatChannel::OnGetUsersRestrictionsResponse);
12 Channel->GetUsersRestrictionsAsync(Callback);
13}
14
15// ACTION REQUIRED: Replace ASample_ChatChannel with name of your Actor class
show all 20 lines

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​

Subscribe to real-time moderation changes for a user with StreamRestrictions(). Bind the user's OnRestrictionChanged delegate before calling this method.

DelegateTypePayload
OnRestrictionChangedFOnPubnubChatUserRestrictionChangedFPubnubChatRestriction containing Ban (bool), Mute (bool), Reason (FString), and ChannelID (FString).

Method signature​

1User->StreamRestrictions();

Output​

TypeDescription
FPubnubChatOperationResultContains Error and ErrorMessage. Check Error to determine if the subscription started successfully.

Sample code​

Actor.h​
1UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatUser")
2void StreamRestrictionsSample();
3
4void OnRestrictionChanged(const FPubnubChatRestriction& Restriction);
Actor.cpp​
1

2// ACTION REQUIRED: Replace ASample_ChatUser with name of your Actor class
3void ASample_ChatUser::StreamRestrictionsSample()
4{
5
6 // Assumes User is a valid UPubnubChatUser (e.g. from GetCurrentUser)
7
8 // Bind to receive moderation restriction changes for this user
9 User->OnRestrictionChangedNative.AddUObject(this, &ASample_ChatUser::OnRestrictionChanged);
10
11 // Start streaming restriction events
12 User->StreamRestrictionsAsync(nullptr);
13
14 // When restriction events are no longer needed, stop streaming
15 User->StopStreamingRestrictionsAsync(nullptr);
show all 22 lines

Stopping updates​

To stop receiving moderation events, call StopStreamingRestrictions() on the user.

1User->StopStreamingRestrictions();

Output​

TypeDescription
FPubnubChatOperationResultContains Error and ErrorMessage.

Was this page useful?

Last updated on