Fix error when enabling a plugin with commands if CommandsAPI hasn't loaded

This commit is contained in:
Vendicated 2022-10-20 19:56:20 +02:00 committed by Ven
parent e4068ef9a6
commit 05051399b6

View file

@ -75,6 +75,15 @@ function modifyOpt(opt: Option | Command) {
} }
export function registerCommand(command: Command, plugin: string) { export function registerCommand(command: Command, plugin: string) {
if (!BUILT_IN) {
console.warn(
"[CommandsAPI]",
`Not registering ${command.name} as the CommandsAPI hasn't been initialised.`,
"Please restart to use commands"
);
return;
}
if (BUILT_IN.some(c => c.name === command.name)) if (BUILT_IN.some(c => c.name === command.name))
throw new Error(`Command '${command.name}' already exists.`); throw new Error(`Command '${command.name}' already exists.`);