Custom Slash Commands
A slash command is a verb you type at the client rather than send to the game.
Your own join the built-in ones on equal terms, sharing the same registry,
listings, and picker, so /greet looks and behaves no different from
/connect.
rune.command.add("greet", function(args) rune.send("say Hello, " .. (args ~= "" and args or "everyone") .. "!")end, "Greet someone")/greet Bob runs this handler. The command appears in /help and the / picker
with its description. Both listings read from the command registry.
Creating
Section titled “Creating”rune.command.add(name, handler, description?, opts?)The command name is one non-empty word without the slash. The handler
receives everything after /name as a single string ("" when there
are no arguments), so multi-word forms such as /pather go town are
expressed as a command plus arguments. The command name doubles as its
registry name.
Options
Section titled “Options”Commands take the common option group.
The command name is the registry name, so re-adding a name replaces
it. Passing name yourself is ignored with a notice.
Examples
Section titled “Examples”A command with subcommands:
rune.command.add("pather", function(args) local sub, rest = args:match("^(%S*)%s*(.*)$") if sub == "go" then pather.go(rest) elseif sub == "stop" then pather.stop() else rune.echo("[Usage] /pather go <place> | /pather stop") endend, "Walk saved paths")Overriding a built-in. Re-adding a name replaces it, so you can wrap.
get returns the command’s handle; :action() is the raw handler:
local quit = assert(rune.command.get("quit")):action()rune.command.add("quit", function(args) rune.send("save") quit(args)end, "Save, then exit")Managing
Section titled “Managing”By name: rune.command.enable/disable/remove(name), plus
rune.command.get(name) for its handle. Full signatures in the
rune.command reference. In the client, /help
lists every command, including script-added ones, with descriptions and
sources.
Gotchas
Section titled “Gotchas”- Commands are quarantined individually: a broken handler can never take down input handling. A disabled command still consumes its input (with an error message).
- Unknown commands report
[Error] Unknown command: /xand are never sent to the server. Use/raw /textif a game actually wants a literal slash.
Related: rune.command reference, Aliases, Built-in slash commands