Skip to content
RustPluginGenerator

OnBroadcastCommand

OnBroadcastCommand is called before the server sends a console command to all connected clients, so a plugin can block or allow the broadcast.

Signature
object OnBroadcastCommand(string command, object[] args)

Parameters

Hook parameters
ParameterTypeDescription
commandstringThe console command string that is about to be sent to every connected client, for example "chat.add 76561198000000000 hello" or a client-side console command.
argsobject[]The argument array the server passed with the command. It may be null; format it with string.Format when the command uses placeholders like {0}.

Return value

Return null to let the broadcast go through unchanged. Returning any non-null value (a true/false object, a string, anything) stops the original method, so the command is never sent to any connected client.

How it works

The hook fires inside ConsoleNetwork.BroadcastToAllClients, the single path the server uses to push a console command to every connection. It runs every time that method is called, before the connection list is iterated, so it covers anything that routes through that method - plugin calls to ConsoleNetwork.BroadcastToAllClients as well as internal server code that uses the same helper. Note that Net.sv.IsConnected() is checked first: if the server is not connected the hook never runs.

command is the raw command text; args is the optional argument array, which can be null. The hook does not expose the target connections because the method has no per-connection information at that point. You can narrow the first parameter to string only - there is no more specific type available, so filtering has to be done by inspecting the command text (StartsWith, contains a substring, or a parsed prefix).

Because every broadcast passes through here, keep the handler cheap. If you return a value, the entire broadcast is skipped for all clients, so use this hook for filtering or for observing server-wide output, not for per-player logic.

Example plugin: Block chat and command broadcasts that match configured filters

BroadcastFilter.cs
using System.Linq;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Broadcast Filter", "RustPluginGenerator", "1.0.0")]
    [Description("Blocks chat and console broadcasts that match configured substrings.")]
    public class BroadcastFilter : RustPlugin
    {
        private const string PermAdmin = "broadcastfilter.admin";

        private PluginConfig config;
        private bool filteringEnabled = true;

        private class PluginConfig
        {
            [JsonProperty("Blocked substrings (lowercase)")]
            public List<string> BlockedSubstrings = new List<string> { "discord.gg/", "free skins" };
        }

        protected override void LoadDefaultConfig() => config = new PluginConfig();

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<PluginConfig>();
                if (config == null) throw new Exception();
            }
            catch
            {
                PrintWarning("Configuration file is invalid, using defaults");
                LoadDefaultConfig();
            }
            SaveConfig();
        }

        protected override void SaveConfig() => Config.WriteObject(config);

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["Enabled"] = "Broadcast filtering is now enabled.",
                ["Disabled"] = "Broadcast filtering is now disabled.",
                ["NoPermission"] = "You do not have permission to use this command."
            }, this);
        }

        private string Msg(string key, string userId = null) => lang.GetMessage(key, this, userId);

        private void Init()
        {
            permission.RegisterPermission(PermAdmin, this);
        }

        [ChatCommand("bcfilter")]
        private void CmdFilter(BasePlayer player, string command, string[] args)
        {
            if (player == null) return;
            if (!permission.UserHasPermission(player.UserIDString, PermAdmin))
            {
                player.ChatMessage(Msg("NoPermission", player.UserIDString));
                return;
            }

            filteringEnabled = !filteringEnabled;
            player.ChatMessage(Msg(filteringEnabled ? "Enabled" : "Disabled", player.UserIDString));
        }

        private object OnBroadcastCommand(string command, object[] args)
        {
            if (!filteringEnabled || string.IsNullOrEmpty(command)) return null;

            string lower = command.ToLowerInvariant();
            foreach (string filter in config.BlockedSubstrings)
            {
                if (!string.IsNullOrEmpty(filter) && lower.Contains(filter))
                {
                    return false;
                }
            }

            return null;
        }
    }
}

The plugin stores a list of blocked substrings in its config. Every time OnBroadcastCommand fires it null-checks command, lowercases it, and compares each configured filter against it. If a filter matches, the broadcast is cancelled for all clients, which stops the matching chat or console output from reaching players. A permission broadcastfilter.admin is required to toggle the filter at runtime with /bcfilter, and the current on/off state is kept in memory. All player-facing messages go through the language file so admins can localize them, and Unload writes the config back to disk.

Common use cases

  • Mute global chat output

    Cancel server-wide chat broadcasts that contain spam keywords or server promotion text while leaving other console output untouched.

  • Audit server-wide commands

    Record or count broadcast commands during a maintenance window to see what your other plugins are pushing to clients.

  • Block specific console commands

    Prevent a client-side console command from being broadcast to everyone when you know it causes problems on your server.

Pitfalls

  • It blocks the broadcast for every player

    There is no per-connection information at this point, so returning a value cancels the command for all clients. For targeted filtering use per-player hooks such as OnMessagePlayer instead.

  • Commands are not always chat

    Many internal console commands (UI, effects, status output) go through the same method. Filtering too broadly can break plugin UI or server messages, so match on specific prefixes.

  • args can be null

    The params array is optional. Always null-check it before formatting the command string, or you will throw inside a frequently called path.

Build a plugin with OnBroadcastCommand

Describe what should happen and get a compiled plugin that uses this hook.

Prompt: Mute global chat output using the OnBroadcastCommand hook, with a config file and a permission
Generate this plugin

Edit the prompt on the next screen. 2 free plugins a month, no card.

Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.

Build a plugin with OnBroadcastCommand

Generate