mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
feat(CommandInteractionOptionResolver): add sub-command required option (#6165)
This commit is contained in:
@@ -97,10 +97,11 @@ class CommandInteractionOptionResolver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the selected sub-command.
|
* 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() {
|
getSubCommand(required = true) {
|
||||||
if (!this._subCommand) {
|
if (required && !this._subCommand) {
|
||||||
throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND');
|
throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND');
|
||||||
}
|
}
|
||||||
return this._subCommand;
|
return this._subCommand;
|
||||||
@@ -108,10 +109,11 @@ class CommandInteractionOptionResolver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the selected sub-command group.
|
* 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() {
|
getSubCommandGroup(required = true) {
|
||||||
if (!this._group) {
|
if (required && !this._group) {
|
||||||
throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP');
|
throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP');
|
||||||
}
|
}
|
||||||
return this._group;
|
return this._group;
|
||||||
|
|||||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -446,8 +446,11 @@ export class CommandInteractionOptionResolver {
|
|||||||
|
|
||||||
public get(name: string, required: true): CommandInteractionOption;
|
public get(name: string, required: true): CommandInteractionOption;
|
||||||
public get(name: string, required?: boolean): CommandInteractionOption | null;
|
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: true): boolean;
|
||||||
public getBoolean(name: string, required?: boolean): boolean | null;
|
public getBoolean(name: string, required?: boolean): boolean | null;
|
||||||
public getChannel(name: string, required: true): NonNullable<CommandInteractionOption['channel']>;
|
public getChannel(name: string, required: true): NonNullable<CommandInteractionOption['channel']>;
|
||||||
|
|||||||
@@ -669,6 +669,13 @@ client.on('interactionCreate', async interaction => {
|
|||||||
assertType<string>(interaction.options.getString('name', true));
|
assertType<string>(interaction.options.getString('name', true));
|
||||||
|
|
||||||
assertType<string>(interaction.options.getSubCommand());
|
assertType<string>(interaction.options.getSubCommand());
|
||||||
|
assertType<string>(interaction.options.getSubCommand(true));
|
||||||
|
assertType<string | null>(interaction.options.getSubCommand(booleanValue));
|
||||||
|
assertType<string | null>(interaction.options.getSubCommand(false));
|
||||||
|
|
||||||
assertType<string>(interaction.options.getSubCommandGroup());
|
assertType<string>(interaction.options.getSubCommandGroup());
|
||||||
|
assertType<string>(interaction.options.getSubCommandGroup(true));
|
||||||
|
assertType<string | null>(interaction.options.getSubCommandGroup(booleanValue));
|
||||||
|
assertType<string | null>(interaction.options.getSubCommandGroup(false));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user