How to use the value of .addChoices

.addStringOption(option =>
option.setName('game')
.setDescription('game')
.setRequired(true)
.addChoices(
{ name: '1', **value**: '1' },
{ name: '2', value: '2' },
{ name: '3', value: '3' },
{ name: '4', value: '4' }
)),
.addStringOption(option =>
option.setName('game')
.setDescription('game')
.setRequired(true)
.addChoices(
{ name: '1', **value**: '1' },
{ name: '2', value: '2' },
{ name: '3', value: '3' },
{ name: '4', value: '4' }
)),
How do I use the 'value' of that code?
7 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Danial
Danial2y ago
<Interaction>.options.getString("game");
박준서
박준서OP2y ago
I want to execute the command with a value.
module.exports = {
data: new SlashCommandBuilder()
.setName(`game`)
.setDescription("game.")
.addChannelOption(option =>
option.setName('channel')
.setDescription('channel.')
.setRequired(true))
.addStringOption(option =>
option.setName('game')
.setDescription('game')
.setRequired(true)
.addChoices(
{ name: '1', **value**: '1' },
{ name: '2', value: '2' },
{ name: '3', value: '3' },
{ name: '4', value: '4' }
)),
async execute(interaction, client) {
const category = interaction.options.getString('game');

await interaction.reply({

});
},
};
module.exports = {
data: new SlashCommandBuilder()
.setName(`game`)
.setDescription("game.")
.addChannelOption(option =>
option.setName('channel')
.setDescription('channel.')
.setRequired(true))
.addStringOption(option =>
option.setName('game')
.setDescription('game')
.setRequired(true)
.addChoices(
{ name: '1', **value**: '1' },
{ name: '2', value: '2' },
{ name: '3', value: '3' },
{ name: '4', value: '4' }
)),
async execute(interaction, client) {
const category = interaction.options.getString('game');

await interaction.reply({

});
},
};
Danial
Danial2y ago
What do you mean by that? Like you want it do something depending on what choice is chosen?
박준서
박준서OP2y ago
If you select a channel and .addChoses, you want to run a command on that channel.
Danial
Danial2y ago
Then get the channel the same way you got the string option value:
const channel = interaction.options.getChannel('channel');
const channel = interaction.options.getChannel('channel');
And then do channel.send() to send a message
d.js docs
d.js docs2y ago
method TextChannel#send() Sends a message to this channel.
Want results from more Discord servers?
Add your server