• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

270
Views
Discord.js v13 choices in options - slash commands

in discordjs.guide is how to set choice in option. But there isn't how to get the choice and how to use it with code. I have /animal command with choices (cat, dog, etc..) and when user click on dog, it send dog picture, same with cat. But i don't know where to put the code for image. I tried and this isn't work, writes This interaction failed. How to do it? Thanks (there is text instead of image for testing)

module.exports = {
    data: new SlashCommandBuilder()
        .setName('animal')
        .setDescription('Sends a animal')
        .addStringOption(option =>
            option.setName('animal')
                .setDescription('Select animal for photo')
                .setRequired(true)
                .addChoice('Cat', 'cat')
                .addChoice('Dog', 'dog')),
    async execute(interaction) {
        if (interaction.options.getString() === 'cat') {
            await interaction.reply('cat')
        } else if (interaction.options.getString() === 'dog') {
            await interaction.reply("dog")
        }
    }
}
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Its simple. You normally do interaction.options.getString('animal');

It will give you cat if the user chooses Cat. So basically it is same as how you normally get a option value

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error