Skip to content

Commit

Permalink
docs(ApplicationCommand): fix and improve localization docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Apr 17, 2022
1 parent 9917981 commit 033bd20
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 27 deletions.
38 changes: 20 additions & 18 deletions packages/discord.js/src/structures/ApplicationCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ApplicationCommand extends Base {
if ('name_localizations' in data) {
/**
* The name localizations for this command
* @type {?Object<string, string>}
* @type {?Object<Locale, string>}
*/
this.nameLocalizations = data.name_localizations;
} else {
Expand All @@ -75,7 +75,7 @@ class ApplicationCommand extends Base {
if ('name_localized' in data) {
/**
* The localized name for this command
* @type {?Object<string, string>}
* @type {?string}
*/
this.nameLocalized = data.name_localized;
} else {
Expand All @@ -93,7 +93,7 @@ class ApplicationCommand extends Base {
if ('description_localizations' in data) {
/**
* The description localizations for this command
* @type {?string}
* @type {?Object<Locale, string>}
*/
this.descriptionLocalizations = data.description_localizations;
} else {
Expand Down Expand Up @@ -169,9 +169,9 @@ class ApplicationCommand extends Base {
* @typedef {Object} ApplicationCommandData
* @property {string} name The name of the command, must be in all lowercase if type is
* {@link ApplicationCommandType.ChatInput}
* @property {Object<string, string>} [nameLocalizations] The localizations for the command name
* @property {Object<Locale, string>} [nameLocalizations] The localizations for the command name
* @property {string} description The description of the command, if type is {@link ApplicationCommandType.ChatInput}
* @property {Object<string, string>} [descriptionLocalizations] The localizations for the command description,
* @property {Object<Locale, string>} [descriptionLocalizations] The localizations for the command description,
* if type is {@link ApplicationCommandType.ChatInput}
* @property {ApplicationCommandType} [type=ApplicationCommandType.ChatInput] The type of the command
* @property {ApplicationCommandOptionData[]} [options] Options for the command
Expand All @@ -188,9 +188,9 @@ class ApplicationCommand extends Base {
* @typedef {Object} ApplicationCommandOptionData
* @property {ApplicationCommandOptionType} type The type of the option
* @property {string} name The name of the option
* @property {Object<string, string>} [nameLocalizations] The name localizations for the option
* @property {Object<Locale, string>} [nameLocalizations] The name localizations for the option
* @property {string} description The description of the option
* @property {Object<string, string>} [descriptionLocalizations] The description localizations for the option
* @property {Object<Locale, string>} [descriptionLocalizations] The description localizations for the option
* @property {boolean} [autocomplete] Whether the autocomplete interaction is enabled for a
* {@link ApplicationCommandOptionType.String}, {@link ApplicationCommandOptionType.Integer} or
* {@link ApplicationCommandOptionType.Number} option
Expand All @@ -208,15 +208,10 @@ class ApplicationCommand extends Base {
/**
* @typedef {Object} ApplicationCommandOptionChoiceData
* @property {string} name The name of the choice
* @property {Object<string, string>} [nameLocalizations] The localized names for this choice
* @property {Object<Locale, string>} [nameLocalizations] The localized names for this choice
* @property {string|number} value The value of the choice
*/

/**
* @typedef {ApplicationCommandOptionChoiceData} ApplicationCommandOptionChoice
* @property {string} [nameLocalized] The localized name for this choice
*/

/**
* Edits this application command.
* @param {ApplicationCommandData} data The data to update the command with
Expand Down Expand Up @@ -244,7 +239,7 @@ class ApplicationCommand extends Base {

/**
* Edits the localized names of this ApplicationCommand
* @param {Object<string, string>} nameLocalizations The new localized names for the command
* @param {Object<Locale, string>} nameLocalizations The new localized names for the command
* @returns {Promise<ApplicationCommand>}
* @example
* // Edit the name localizations of this command
Expand All @@ -270,11 +265,11 @@ class ApplicationCommand extends Base {

/**
* Edits the localized descriptions of this ApplicationCommand
* @param {Object<string, string>} descriptionLocalizations The new localized descriptions for the command
* @param {Object<Locale, string>} descriptionLocalizations The new localized descriptions for the command
* @returns {Promise<ApplicationCommand>}
* @example
* // Edit the description localizations of this command
* command.setLocalizedDescriptions({
* command.setDescriptionLocalizations({
* 'en-GB': 'A test command',
* 'pt-BR': 'Um comando de teste',
* })
Expand Down Expand Up @@ -440,10 +435,8 @@ class ApplicationCommand extends Base {
* @property {ApplicationCommandOptionType} type The type of the option
* @property {string} name The name of the option
* @property {Object<string, string>} [nameLocalizations] The localizations for the option name
* @property {string} [nameLocalized] The localized name for this option
* @property {string} description The description of the option
* @property {Object<string, string>} [descriptionLocalizations] The localizations for the option description
* @property {string} [descriptionLocalized] The localized description for this option
* @property {boolean} [required] Whether the option is required
* @property {boolean} [autocomplete] Whether the autocomplete interaction is enabled for a
* {@link ApplicationCommandOptionType.String}, {@link ApplicationCommandOptionType.Integer} or
Expand All @@ -458,6 +451,15 @@ class ApplicationCommand extends Base {
* {@link ApplicationCommandOptionType.Number} option
*/

/**
* A choice for an application command option.
* @typedef {Object} ApplicationCommandOptionChoice
* @property {string} name The name of the choice
* @property {?string} nameLocalized The localized name of the choice in the provided locale, if any
* @property {?Object<string, string>} [nameLocalizations] The localized names for this choice
* @property {string|number} value The value of the choice
*/

/**
* Transforms an {@link ApplicationCommandOptionData} object into something that can be used with the API.
* @param {ApplicationCommandOptionData|ApplicationCommandOption} option The option to transform
Expand Down
3 changes: 1 addition & 2 deletions packages/discord.js/src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ class Guild extends AnonymousGuild {
if ('preferred_locale' in data) {
/**
* The preferred locale of the guild, defaults to `en-US`
* @type {string}
* @see {@link https://discord.com/developers/docs/reference#locales}
* @type {Locale}
*/
this.preferredLocale = data.preferred_locale;
}
Expand Down
41 changes: 38 additions & 3 deletions packages/discord.js/src/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,50 @@ class Interaction extends Base {
: null;

/**
* The locale of the user who invoked this interaction
* @type {string}
* A Discord locale string, possible values are:
* * en-US (English, US)
* * en-GB (English, UK)
* * bg (Bulgarian)
* * zh-CN (Chinese, China)
* * zh-TW (Chinese, Taiwan)
* * hr (Croatian)
* * cs (Czech)
* * da (Danish)
* * nl (Dutch)
* * fi (Finnish)
* * fr (French)
* * de (German)
* * el (Greek)
* * hi (Hindi)
* * hu (Hungarian)
* * it (Italian)
* * ja (Japanese)
* * ko (Korean)
* * lt (Lithuanian)
* * no (Norwegian)
* * pl (Polish)
* * pt-BR (Portuguese, Brazilian)
* * ro (Romanian, Romania)
* * ru (Russian)
* * es-ES (Spanish)
* * sv-SE (Swedish)
* * th (Thai)
* * tr (Turkish)
* * uk (Ukrainian)
* * vi (Vietnamese)
* @see {@link https://discord.com/developers/docs/reference#locales}
* @typedef {string} Locale
*/

/**
* The locale of the user who invoked this interaction
* @type {Locale}
*/
this.locale = data.locale;

/**
* The preferred locale from the guild this interaction was sent in
* @type {?string}
* @type {?Locale}
*/
this.guildLocale = data.guild_locale ?? null;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3595,10 +3595,6 @@ export interface ApplicationCommandOptionChoiceData {
value: string | number;
}

export interface ApplicationCommandOptionChoice extends ApplicationCommandOptionChoiceData {
nameLocalized?: string;
}

export interface ApplicationCommandPermissionData {
id: Snowflake;
type: ApplicationCommandPermissionType;
Expand Down

0 comments on commit 033bd20

Please sign in to comment.