Skip to main content

Overview

ICommandManager manages registered in-game slash commands. It allows plugins to register custom commands that players can use in the chat window.

Namespace

Dalamud.Plugin.Services

Properties

Commands

public ReadOnlyDictionary<string, IReadOnlyCommandInfo> Commands { get; }
Gets a read-only list of all registered commands.
Commands
ReadOnlyDictionary<string, IReadOnlyCommandInfo>
Dictionary of all registered commands, keyed by command name

Methods

ProcessCommand

public bool ProcessCommand(string content);
Processes a command in full.
content
string
required
The full command string including the command name and arguments
return
bool
True if the command was found and dispatched

DispatchCommand

public void DispatchCommand(string command, string argument, IReadOnlyCommandInfo info);
Dispatches the handling of a command.
command
string
required
The command to dispatch
argument
string
required
The provided arguments
info
IReadOnlyCommandInfo
required
A CommandInfo object describing this command

AddHandler

public bool AddHandler(string command, CommandInfo info);
Adds a command handler, which you can use to add your own custom commands to the in-game chat.
command
string
required
The command to register (e.g., “/mycommand”)
info
CommandInfo
required
A CommandInfo object describing the command
return
bool
True if adding was successful, false if the command already exists

RemoveHandler

public bool RemoveHandler(string command);
Removes a command from the command handlers.
command
string
required
The command to remove
return
bool
True if the removal was successful, false if the command was not found

Example Usage

public class MyPlugin : IDalamudPlugin
{
    private readonly ICommandManager commandManager;
    private const string CommandName = "/mycommand";
    
    public MyPlugin(ICommandManager commandManager)
    {
        this.commandManager = commandManager;
        
        // Register a command
        this.commandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
        {
            HelpMessage = "Displays a greeting message",
            ShowInHelp = true
        });
    }
    
    private void OnCommand(string command, string args)
    {
        // Parse arguments
        if (string.IsNullOrEmpty(args))
        {
            Log.Information("Hello, World!");
        }
        else
        {
            Log.Information($"Hello, {args}!");
        }
    }
    
    public void Dispose()
    {
        this.commandManager.RemoveHandler(CommandName);
    }
}

Advanced Usage

Command with Multiple Arguments

private void OnCommand(string command, string args)
{
    var splitArgs = args.Split(' ', StringSplitOptions.RemoveEmptyEntries);
    
    if (splitArgs.Length == 0)
    {
        // No arguments provided
        return;
    }
    
    switch (splitArgs[0].ToLower())
    {
        case "show":
            // Handle show subcommand
            break;
        case "hide":
            // Handle hide subcommand
            break;
        default:
            // Unknown subcommand
            break;
    }
}

Command with Help Text

this.commandManager.AddHandler("/mycommand", new CommandInfo(OnCommand)
{
    HelpMessage = "Usage: /mycommand [show|hide] - Controls window visibility",
    ShowInHelp = true
});

Remarks

  • Command names must start with a forward slash (/)
  • Command names are case-insensitive
  • Always remove command handlers in your plugin’s Dispose() method
  • The HelpMessage will be displayed when players use /xlhelp
  • Multiple plugins cannot register the same command name

Build docs developers (and LLMs) love