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 toolkit15mo 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
Danial15mo ago
<Interaction>.options.getString("game");
박준서
박준서15mo 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
Danial15mo ago
What do you mean by that? Like you want it do something depending on what choice is chosen?
박준서
박준서15mo ago
If you select a channel and .addChoses, you want to run a command on that channel.
Danial
Danial15mo 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 docs15mo ago
method TextChannel#send() Sends a message to this channel.