diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index b317f32d5..348e091a6 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -97,10 +97,11 @@ class CommandInteractionOptionResolver { /** * Gets the selected sub-command. - * @returns {string} The name of the selected sub-command. + * @param {boolean} [required=true] Whether to throw an error if there is no sub-command. + * @returns {?string} The name of the selected sub-command, or null if not set and not required. */ - getSubCommand() { - if (!this._subCommand) { + getSubCommand(required = true) { + if (required && !this._subCommand) { throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND'); } return this._subCommand; @@ -108,10 +109,11 @@ class CommandInteractionOptionResolver { /** * Gets the selected sub-command group. - * @returns {string} The name of the selected sub-command group. + * @param {boolean} [required=true] Whether to throw an error if there is no sub-command group. + * @returns {?string} The name of the selected sub-command group, or null if not set and not required. */ - getSubCommandGroup() { - if (!this._group) { + getSubCommandGroup(required = true) { + if (required && !this._group) { throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP'); } return this._group; diff --git a/typings/index.d.ts b/typings/index.d.ts index c99166224..639df52ac 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -446,8 +446,11 @@ export class CommandInteractionOptionResolver { public get(name: string, required: true): CommandInteractionOption; public get(name: string, required?: boolean): CommandInteractionOption | null; - public getSubCommand(): string; - public getSubCommandGroup(): string; + + public getSubCommand(required?: true): string; + public getSubCommand(required: boolean): string | null; + public getSubCommandGroup(required?: true): string; + public getSubCommandGroup(required: boolean): string | null; public getBoolean(name: string, required: true): boolean; public getBoolean(name: string, required?: boolean): boolean | null; public getChannel(name: string, required: true): NonNullable; diff --git a/typings/index.ts b/typings/index.ts index c4668555c..6cdc2d4c4 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -669,6 +669,13 @@ client.on('interactionCreate', async interaction => { assertType(interaction.options.getString('name', true)); assertType(interaction.options.getSubCommand()); + assertType(interaction.options.getSubCommand(true)); + assertType(interaction.options.getSubCommand(booleanValue)); + assertType(interaction.options.getSubCommand(false)); + assertType(interaction.options.getSubCommandGroup()); + assertType(interaction.options.getSubCommandGroup(true)); + assertType(interaction.options.getSubCommandGroup(booleanValue)); + assertType(interaction.options.getSubCommandGroup(false)); } });