diff --git a/src/api/Commands.ts b/src/api/Commands.ts index 907a65d..f7f42e9 100644 --- a/src/api/Commands.ts +++ b/src/api/Commands.ts @@ -45,7 +45,9 @@ export function generateId() { * @param fallbackValue Fallback value in case this option wasn't passed * @returns Value */ -export function findOption(args: Argument[], name: string, fallbackValue?: T): T extends undefined ? T : string { +export function findOption(args: Argument[], name: string): T & {} | undefined; +export function findOption(args: Argument[], name: string, fallbackValue: T): T & {}; +export function findOption(args: Argument[], name: string, fallbackValue?: any) { return (args.find(a => a.name === name)?.value || fallbackValue) as any; } @@ -64,10 +66,10 @@ export function registerCommand(command: Command, plugin: string) { if (BUILT_IN.some(c => c.name === command.name)) throw new Error(`Command '${command.name}' already exists.`); - command.id ||= generateId(); - command.applicationId ||= "-1"; // BUILT_IN; - command.type ||= ApplicationCommandType.CHAT_INPUT; - command.inputType ||= ApplicationCommandInputType.BUILT_IN_TEXT; + command.id ??= generateId(); + command.applicationId ??= "-1"; // BUILT_IN; + command.type ??= ApplicationCommandType.CHAT_INPUT; + command.inputType ??= ApplicationCommandInputType.BUILT_IN_TEXT; command.plugin ||= plugin; modifyOpt(command); @@ -155,5 +157,5 @@ export interface Command { options?: Option[]; predicate?(ctx: CommandContext): boolean; - execute(args: Argument[], ctx: CommandContext): CommandReturnValue | void; + execute(args: Argument[], ctx: CommandContext): CommandReturnValue | void | Promise; }