Function: createLocalizedChoice()
createLocalizedChoice<
ValueType
,TOpt
,Ns
,KPrefix
>(key
:string
,options
:Omit
<APIApplicationCommandOptionChoice
<ValueType
>,"name"
|"name_localizations"
>):APIApplicationCommandOptionChoice
<ValueType
>
Constructs an object that can be passed into setChoices
for String or Number option with localized names.
Type Parameters
Type Parameter | Default type |
---|---|
ValueType | string | number |
TOpt extends TOptions | TOptions |
Ns extends Namespace | "translation" |
KPrefix | undefined |
Parameters
Parameter | Type | Description |
---|---|---|
key | string | The i18next key for the name of the select option name. |
options | Omit <APIApplicationCommandOptionChoice <ValueType >, "name" | "name_localizations" > | The additional Select Menu options. This should at least include the value key. |
Returns
APIApplicationCommandOptionChoice
<ValueType
>
An object with anything provided through createLocalizedChoice.options with name
and name_localizations
added.
Example
export class TypeCommand extends Command {
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand((builder) =>
applyLocalizedBuilder(builder, 'commands/names:type').addStringOption((option) =>
applyLocalizedBuilder(option, 'commands/options:type')
.setRequired(true)
.setChoices(
createLocalizedChoice('selects/pokemon:type-grass', { value: 'grass' }),
createLocalizedChoice('selects/pokemon:type-water', { value: 'water' }),
createLocalizedChoice('selects/pokemon:type-fire', { value: 'fire' }),
createLocalizedChoice('selects/pokemon:type-electric', { value: 'electric' })
)
)
);
}
}