Entering commands in game
Type /toolbox or /8 in chat to switch to the Toolbox command line, then enter a command. You can also supply it directly:
/toolbox mymod
/toolbox mymod echo "Hello world"
/toolbox mymod echo 'A quoted string'
/toolbox mymod echo "Quotes: \"example\"; backslash: \\"
Spaces separate arguments. Use single or double quotes for strings containing spaces. A backslash escapes quotes and backslashes. Unclosed quotes cause a parse error. Callbacks receive strings: convert and validate numbers and booleans yourself.
Registration
mod.command exposes the built-in command module. add(command, callback[, context]) accepts a name or an array of aliases. Names must be unique, case-insensitively; registering an occupied name throws. context supplies the callback's this.
module.exports = function MyMod(mod) {
mod.command.add(['mymod', 'mm'], (...args) => {
mod.command.message(`Arguments: ${args.join(', ')}`);
});
};
Subcommands
You can pass an object instead of a function. Keys become subcommands; nested objects create another level. $none handles missing arguments; $default handles unmatched commands. $default also receives the unmatched subcommand name.
mod.command.add('example', {
$none() {
mod.command.message('Usage: example echo <text> | color blue');
},
$default(name) {
mod.command.message(`Unknown subcommand: ${name}`);
},
echo(...words) {
mod.command.message(words.join(' '));
},
color: {
$default() { mod.command.message('Usage: example color blue'); },
blue() { mod.command.message('<font color="#5555ff">Hello!</font>'); }
}
});
Other methods
| Method | Behavior |
|---|---|
remove(command) |
Removes a command or an array of aliases |
message(msg) |
Sends to the Toolbox channel; supports game HTML markup |
exec(str) |
Executes a raw command string without /toolbox |
exec(args) |
Executes an array of already separated arguments |
exec returns true when a command is found and false otherwise; callback errors can propagate to the caller. message prefixes the module name according to command settings. Commands registered through mod.command are removed when its interface is destroyed; explicitly call remove when temporarily disabling a feature. Do not insert unchecked text into message HTML attributes.
Sources: mods/command/README.md, mods/command/index.js, bin/mod.js. The original command module was created by Pinkie Pie; Toolbox extends it and integrates it into the module API.