繁体   English   中英

Discord.js v13 选项中的选项 - 斜杠命令

[英]Discord.js v13 choices in options - slash commands

discordjs.guide中是如何在选项中设置选项。 但是没有如何获得选择以及如何将其与代码一起使用。 我有带有选项(猫、狗等)的 /animal 命令,当用户单击狗时,它会发送狗图片,与猫相同。 但我不知道将图像代码放在哪里。 我试过了,但这是行不通的,写道This interaction failed 怎么做? 谢谢(有文本而不是图像进行测试)

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")
        }
    }
}

这很简单。 你通常会做interaction.options.getString('animal');

如果用户选择Cat ,它会给你cat 所以基本上它和你通常如何获得一个期权价值是一样的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM