Guides
Syntax validation
Reject bad command definitions while the bot starts.
SWAGcommands validates command files as it loads them. Built-in syntax checks require a callback on normal commands, a description on slash-capable commands, and a valid deferReply setting. Subcommands and context menus have their own shape checks.
You can add definition-time validation functions in a directory and pass it as validations.syntax:
await SWAG.create({
client,
commandsDir: "./dist/commands",
validations: { syntax: "./dist/validations" },
});export default function noSpaces(command: { commandName: string }) {
if (/\s/.test(command.commandName)) {
throw new Error(`Command ${command.commandName} contains whitespace.`);
}
}Validation modules must default-export functions. They run while normal commands, subcommand roots and leaves, and context menus load. A thrown error fails initialization; the bot doesn't start with a partly validated registry. Use this for definition rules, not user permission checks. The latter belong in preconditions.