Option values

So I have this option with choices
{
name: 'punishment-type',
type: ApplicationCommandOptionType.String,
description: 'Type of punishment',
required: true,
choices: [
{
name: 'Game Ban',
value: 'game-ban',
},
{
name: 'Server Ban',
value: 'server-ban',
},
{
name: 'Kick',
value: 'server-kick',
},
{
name: 'Warning',
value: 'server-warning',
},
],
},
{
name: 'punishment-type',
type: ApplicationCommandOptionType.String,
description: 'Type of punishment',
required: true,
choices: [
{
name: 'Game Ban',
value: 'game-ban',
},
{
name: 'Server Ban',
value: 'server-ban',
},
{
name: 'Kick',
value: 'server-kick',
},
{
name: 'Warning',
value: 'server-warning',
},
],
},
And to get the value i use
const punishmentTypeValue = interaction.options.get('punishment-type')?.value || 'No punishment type provided';
const punishmentTypeValue = interaction.options.get('punishment-type')?.value || 'No punishment type provided';
I was wondering instead of the choice value is it possible to get the choice name ? I cannot seem to figure out how..
7 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
treble/luna
treble/luna6mo ago
no just make your name the same as your value if you want that
JoelHCraft
JoelHCraft6mo ago
I tried using .name and it returns server-ban I want it to say Server Ban
treble/luna
treble/luna6mo ago
then make your value that instead of lowercase also use options.getString() not get()?.value
JoelHCraft
JoelHCraft6mo ago
const punishmentTypeValue = interaction.options.getString('punishment-type')?.name
const punishmentTypeValue = interaction.options.getString('punishment-type')?.name
name does not work
treble/luna
treble/luna6mo ago
because you cannot access an option name as i told you
JoelHCraft
JoelHCraft6mo ago
Ta