Overloads allow a single command to support multiple different argument structures. You define them within the registry function using registry.overload(args, executor).
Argument Definition:
Arguments are defined as an object where keys are the argument names. The value is an array containing:
- The Argument Type (e.g.,
TargetEnum, CustomEnum, or a class extending CustomEnum). - A boolean indicating if the argument is optional (
false means it is required).
Executor Context:
The overload executor receives an object containing the results of the parsed arguments (e.g., { target, kit }).
import { TargetEnum, World } from "@serenityjs/core";
function register(world: World): void {
world.commandPalette.register(
"ping",
"Ping the server to check if it's responsive.",
(registry) => {
registry.overload(
{
target: [TargetEnum, false] // Required argument
},
({ target }) => {
// target.result contains the parsed entities
const value = target.result[0].isPlayer()
? target.result[0].username
: target.result[0].type.identifier;
return { message: `Pong, ${value}!` };
}
);
},
() => { return { message: "Pong!" }; }
);
}