mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: Match subcommand (group) name casing with Discord's (#6204)
This commit is contained in:
@@ -138,8 +138,8 @@ const Messages = {
|
||||
`Option "${name}" is of type: ${type}; expected ${expected}.`,
|
||||
COMMAND_INTERACTION_OPTION_EMPTY: (name, type) =>
|
||||
`Required option "${name}" is of type: ${type}; expected a non-empty value.`,
|
||||
COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND: 'No sub-command specified for interaction.',
|
||||
COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP: 'No sub-command group specified for interaction.',
|
||||
COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND: 'No subcommand specified for interaction.',
|
||||
COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP: 'No subcommand group specified for interaction.',
|
||||
|
||||
INVITE_MISSING_SCOPES: 'At least one valid scope must be provided for the invite',
|
||||
|
||||
|
||||
@@ -16,35 +16,35 @@ class CommandInteractionOptionResolver {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
/**
|
||||
* The name of the sub-command group.
|
||||
* The name of the subcommand group.
|
||||
* @type {?string}
|
||||
* @private
|
||||
*/
|
||||
this._group = null;
|
||||
|
||||
/**
|
||||
* The name of the sub-command.
|
||||
* The name of the subcommand.
|
||||
* @type {?string}
|
||||
* @private
|
||||
*/
|
||||
this._subCommand = null;
|
||||
this._subcommand = null;
|
||||
|
||||
/**
|
||||
* The bottom-level options for the interaction.
|
||||
* If there is a sub-command (or sub-command and group), this is the options for the sub-command.
|
||||
* If there is a subcommand (or subcommand and group), this is the options for the subcommand.
|
||||
* @type {CommandInteractionOption[]}
|
||||
* @private
|
||||
*/
|
||||
this._hoistedOptions = options;
|
||||
|
||||
// Hoist sub-command group if present
|
||||
// Hoist subcommand group if present
|
||||
if (this._hoistedOptions[0]?.type === 'SUB_COMMAND_GROUP') {
|
||||
this._group = this._hoistedOptions[0].name;
|
||||
this._hoistedOptions = this._hoistedOptions[0].options ?? [];
|
||||
}
|
||||
// Hoist sub-command if present
|
||||
// Hoist subcommand if present
|
||||
if (this._hoistedOptions[0]?.type === 'SUB_COMMAND') {
|
||||
this._subCommand = this._hoistedOptions[0].name;
|
||||
this._subcommand = this._hoistedOptions[0].name;
|
||||
this._hoistedOptions = this._hoistedOptions[0].options ?? [];
|
||||
}
|
||||
|
||||
@@ -96,23 +96,23 @@ class CommandInteractionOptionResolver {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets 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.
|
||||
* Gets the selected subcommand.
|
||||
* @param {boolean} [required=true] Whether to throw an error if there is no subcommand.
|
||||
* @returns {?string} The name of the selected subcommand, or null if not set and not required.
|
||||
*/
|
||||
getSubCommand(required = true) {
|
||||
if (required && !this._subCommand) {
|
||||
getSubcommand(required = true) {
|
||||
if (required && !this._subcommand) {
|
||||
throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND');
|
||||
}
|
||||
return this._subCommand;
|
||||
return this._subcommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets 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.
|
||||
* Gets the selected subcommand group.
|
||||
* @param {boolean} [required=true] Whether to throw an error if there is no subcommand group.
|
||||
* @returns {?string} The name of the selected subcommand group, or null if not set and not required.
|
||||
*/
|
||||
getSubCommandGroup(required = true) {
|
||||
getSubcommandGroup(required = true) {
|
||||
if (required && !this._group) {
|
||||
throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP');
|
||||
}
|
||||
|
||||
10
typings/index.d.ts
vendored
10
typings/index.d.ts
vendored
@@ -431,7 +431,7 @@ export class CommandInteractionOptionResolver {
|
||||
public readonly data: readonly CommandInteractionOption[];
|
||||
private _group: string | null;
|
||||
private _hoistedOptions: CommandInteractionOption[];
|
||||
private _subCommand: string | null;
|
||||
private _subcommand: string | null;
|
||||
private _getTypedOption(
|
||||
name: string,
|
||||
type: ApplicationCommandOptionType,
|
||||
@@ -448,10 +448,10 @@ export class CommandInteractionOptionResolver {
|
||||
public get(name: string, required: true): CommandInteractionOption;
|
||||
public get(name: string, required?: boolean): CommandInteractionOption | null;
|
||||
|
||||
public getSubCommand(required?: true): string;
|
||||
public getSubCommand(required: boolean): string | null;
|
||||
public getSubCommandGroup(required?: true): string;
|
||||
public getSubCommandGroup(required: boolean): string | null;
|
||||
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<CommandInteractionOption['channel']>;
|
||||
|
||||
@@ -668,14 +668,14 @@ client.on('interactionCreate', async interaction => {
|
||||
assertType<string | null>(interaction.options.getString('name', false));
|
||||
assertType<string>(interaction.options.getString('name', true));
|
||||
|
||||
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.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(true));
|
||||
assertType<string | null>(interaction.options.getSubCommandGroup(booleanValue));
|
||||
assertType<string | null>(interaction.options.getSubCommandGroup(false));
|
||||
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