For the complete documentation index, see llms.txt. This page is also available as Markdown.

Chat Commands

Adding chat commands is as easy as making your method public static and adding the ChatCommand attribute as shown below.

Example Simple Command Without Permissions

[ChatCommand("discord")]
public static void DiscordCommand(Player player)
{
    player.SendChatMessage("You can join our discord at discord.gg/xxxxx");
}

A command with a description and a required permission.

[ChatCommand(name: "kickme", permission: "chat.kickme", docs: "Syntax: '/kickme' Kicks yourself from the server.")]
public static void Command_players(Player player)
{
    player.Kick("Such an useful command.");
}

As an example here is the players command from SDS.

This command uses a string as the return type for ease of use, it directly sends the message in chat OR in the console if ran by the console. If a command is ran by the console the player will be null. The player can NEVER be null in other cases. The console also bypass any permissions.

[ChatCommand(name: "players", permission: "chat.players", docs: "Syntax: '/players' Lists all players in the world.")]
public static string Command_players(Player player, string[] args)
{
    List<Player> players = Player.PlayerList.WithoutServerPlayer();
    string playerList = string.Join(", ", players.Select(x => x.PlayerName));
    return $"Players ({players.Count}): {playerList}.";
}

Last updated