@@ -62,6 +62,26 @@ class ApplicationCommand extends Base {
62
62
this . name = data . name ;
63
63
}
64
64
65
+ if ( 'name_localizations' in data ) {
66
+ /**
67
+ * The name localizations for this command
68
+ * @type {?Object<string, string> }
69
+ */
70
+ this . nameLocalizations = data . name_localizations ;
71
+ } else {
72
+ this . nameLocalizations ??= null ;
73
+ }
74
+
75
+ if ( 'name_localized' in data ) {
76
+ /**
77
+ * The localized name for this command
78
+ * @type {?Object<string, string> }
79
+ */
80
+ this . nameLocalized = data . name_localized ;
81
+ } else {
82
+ this . nameLocalized ??= null ;
83
+ }
84
+
65
85
if ( 'description' in data ) {
66
86
/**
67
87
* The description of this command
@@ -70,6 +90,26 @@ class ApplicationCommand extends Base {
70
90
this . description = data . description ;
71
91
}
72
92
93
+ if ( 'description_localizations' in data ) {
94
+ /**
95
+ * The description localizations for this command
96
+ * @type {?string }
97
+ */
98
+ this . descriptionLocalizations = data . description_localizations ;
99
+ } else {
100
+ this . descriptionLocalizations ??= null ;
101
+ }
102
+
103
+ if ( 'description_localized' in data ) {
104
+ /**
105
+ * The localized description for this command
106
+ * @type {?string }
107
+ */
108
+ this . descriptionLocalized = data . description_localized ;
109
+ } else {
110
+ this . descriptionLocalized ??= null ;
111
+ }
112
+
73
113
if ( 'options' in data ) {
74
114
/**
75
115
* The options of this command
@@ -128,7 +168,9 @@ class ApplicationCommand extends Base {
128
168
* Data for creating or editing an application command.
129
169
* @typedef {Object } ApplicationCommandData
130
170
* @property {string } name The name of the command
171
+ * @property {Object<string, string> } [nameLocalizations] The localizations for the command name
131
172
* @property {string } description The description of the command
173
+ * @property {Object<string, string> } [descriptionLocalizations] The localizations for the command description
132
174
* @property {ApplicationCommandType } [type] The type of the command
133
175
* @property {ApplicationCommandOptionData[] } [options] Options for the command
134
176
* @property {boolean } [defaultPermission] Whether the command is enabled by default when the app is added to a guild
@@ -143,17 +185,31 @@ class ApplicationCommand extends Base {
143
185
* @typedef {Object } ApplicationCommandOptionData
144
186
* @property {ApplicationCommandOptionType|number } type The type of the option
145
187
* @property {string } name The name of the option
188
+ * @property {Object<string, string> } [nameLocalizations] The name localizations for the option
146
189
* @property {string } description The description of the option
190
+ * @property {Object<string, string> } [descriptionLocalizations] The description localizations for the option
147
191
* @property {boolean } [autocomplete] Whether the option is an autocomplete option
148
192
* @property {boolean } [required] Whether the option is required
149
- * @property {ApplicationCommandOptionChoice [] } [choices] The choices of the option for the user to pick from
193
+ * @property {ApplicationCommandOptionChoiceData [] } [choices] The choices of the option for the user to pick from
150
194
* @property {ApplicationCommandOptionData[] } [options] Additional options if this option is a subcommand (group)
151
195
* @property {ChannelType[]|number[] } [channelTypes] When the option type is channel,
152
196
* the allowed types of channels that can be selected
153
197
* @property {number } [minValue] The minimum value for an `INTEGER` or `NUMBER` option
154
198
* @property {number } [maxValue] The maximum value for an `INTEGER` or `NUMBER` option
155
199
*/
156
200
201
+ /**
202
+ * @typedef {Object } ApplicationCommandOptionChoiceData
203
+ * @property {string } name The name of the choice
204
+ * @property {Object<string, string> } [nameLocalizations] The localized names for this choice
205
+ * @property {string|number } value The value of the choice
206
+ */
207
+
208
+ /**
209
+ * @param {ApplicationCommandOptionChoiceData } ApplicationCommandOptionChoice
210
+ * @property {string } [nameLocalized] The localized name for this choice
211
+ */
212
+
157
213
/**
158
214
* Edits this application command.
159
215
* @param {ApplicationCommandData } data The data to update the command with
@@ -179,6 +235,23 @@ class ApplicationCommand extends Base {
179
235
return this . edit ( { name } ) ;
180
236
}
181
237
238
+ /**
239
+ * Edits the localized names of this ApplicationCommand
240
+ * @param {Object<string, string> } nameLocalizations The new localized names for the command
241
+ * @returns {Promise<ApplicationCommand> }
242
+ * @example
243
+ * // Edit the name localizations of this command
244
+ * command.setLocalizedNames({
245
+ * 'en-GB': 'test',
246
+ * 'pt-BR': 'teste',
247
+ * })
248
+ * .then(console.log)
249
+ * .catch(console.error)
250
+ */
251
+ setNameLocalizations ( nameLocalizations ) {
252
+ return this . edit ( { nameLocalizations } ) ;
253
+ }
254
+
182
255
/**
183
256
* Edits the description of this ApplicationCommand
184
257
* @param {string } description The new description of the command
@@ -188,6 +261,23 @@ class ApplicationCommand extends Base {
188
261
return this . edit ( { description } ) ;
189
262
}
190
263
264
+ /**
265
+ * Edits the localized descriptions of this ApplicationCommand
266
+ * @param {Object<string, string> } descriptionLocalizations The new localized descriptions for the command
267
+ * @returns {Promise<ApplicationCommand> }
268
+ * @example
269
+ * // Edit the description localizations of this command
270
+ * command.setLocalizedDescriptions({
271
+ * 'en-GB': 'A test command',
272
+ * 'pt-BR': 'Um comando de teste',
273
+ * })
274
+ * .then(console.log)
275
+ * .catch(console.error)
276
+ */
277
+ setDescriptionLocalizations ( descriptionLocalizations ) {
278
+ return this . edit ( { descriptionLocalizations } ) ;
279
+ }
280
+
191
281
/**
192
282
* Edits the default permission of this ApplicationCommand
193
283
* @param {boolean } [defaultPermission=true] The default permission for this command
@@ -344,7 +434,11 @@ class ApplicationCommand extends Base {
344
434
* @typedef {Object } ApplicationCommandOption
345
435
* @property {ApplicationCommandOptionType } type The type of the option
346
436
* @property {string } name The name of the option
437
+ * @property {Object<string, string> } [nameLocalizations] The localizations for the option name
438
+ * @property {string } [nameLocalized] The localized name for this option
347
439
* @property {string } description The description of the option
440
+ * @property {Object<string, string> } [descriptionLocalizations] The localizations for the option description
441
+ * @property {string } [descriptionLocalized] The localized description for this option
348
442
* @property {boolean } [required] Whether the option is required
349
443
* @property {boolean } [autocomplete] Whether the option is an autocomplete option
350
444
* @property {ApplicationCommandOptionChoice[] } [choices] The choices of the option for the user to pick from
@@ -359,12 +453,14 @@ class ApplicationCommand extends Base {
359
453
* A choice for an application command option.
360
454
* @typedef {Object } ApplicationCommandOptionChoice
361
455
* @property {string } name The name of the choice
456
+ * @property {string } [nameLocalized] The localized name for this choice
457
+ * @property {Object<string, string> } [nameLocalizations] The localized names for this choice
362
458
* @property {string|number } value The value of the choice
363
459
*/
364
460
365
461
/**
366
462
* Transforms an {@link ApplicationCommandOptionData} object into something that can be used with the API.
367
- * @param {ApplicationCommandOptionData } option The option to transform
463
+ * @param {ApplicationCommandOptionData|ApplicationCommandOption } option The option to transform
368
464
* @param {boolean } [received] Whether this option has been received from Discord
369
465
* @returns {APIApplicationCommandOption }
370
466
* @private
@@ -374,14 +470,27 @@ class ApplicationCommand extends Base {
374
470
const channelTypesKey = received ? 'channelTypes' : 'channel_types' ;
375
471
const minValueKey = received ? 'minValue' : 'min_value' ;
376
472
const maxValueKey = received ? 'maxValue' : 'max_value' ;
473
+ const nameLocalizationsKey = received ? 'nameLocalizations' : 'name_localizations' ;
474
+ const nameLocalizedKey = received ? 'nameLocalized' : 'name_localized' ;
475
+ const descriptionLocalizationsKey = received ? 'descriptionLocalizations' : 'description_localizations' ;
476
+ const descriptionLocalizedKey = received ? 'descriptionLocalized' : 'description_localized' ;
377
477
return {
378
478
type : typeof option . type === 'number' && ! received ? option . type : ApplicationCommandOptionTypes [ option . type ] ,
379
479
name : option . name ,
480
+ [ nameLocalizationsKey ] : option . nameLocalizations ?? option . name_localizations ,
481
+ [ nameLocalizedKey ] : option . nameLocalized ?? option . name_localized ,
380
482
description : option . description ,
483
+ [ descriptionLocalizationsKey ] : option . descriptionLocalizations ?? option . description_localizations ,
484
+ [ descriptionLocalizedKey ] : option . descriptionLocalized ?? option . description_localized ,
381
485
required :
382
486
option . required ?? ( stringType === 'SUB_COMMAND' || stringType === 'SUB_COMMAND_GROUP' ? undefined : false ) ,
383
487
autocomplete : option . autocomplete ,
384
- choices : option . choices ,
488
+ choices : option . choices ?. map ( choice => ( {
489
+ name : choice . name ,
490
+ [ nameLocalizedKey ] : choice . nameLocalized ?? choice . name_localized ,
491
+ [ nameLocalizationsKey ] : choice . nameLocalizations ?? choice . name_localizations ,
492
+ value : choice . value ,
493
+ } ) ) ,
385
494
options : option . options ?. map ( o => this . transformOption ( o , received ) ) ,
386
495
[ channelTypesKey ] : received
387
496
? option . channel_types ?. map ( type => ChannelTypes [ type ] )
0 commit comments