当我选择问题时,未显示答案值。我希望显示问题和答案。
选择问题:https://ibb.co/6sYLc1P
const { SlashCommandBuilder } = require("@discordjs/builders")
module.exports = {
data: new SlashCommandBuilder()
.setName("question")
.setDescription("what do you want to ask me?")
.addStringOption(option =>
option.setName('question')
.setDescription('Your question')
.setRequired(true)
.addChoices(
{ name: 'How old are you', value: '21' },
{ name: 'When is your birthday?', value: 'September 8, 2003' },
{ name: 'What is your favorite color?', value: 'Violet' },
)),
execute: async ({ interaction }) => {
await interaction.reply({ content: 'your question: ${name}' });
await interaction.reply({ content: 'answer: ${value}' })
}
}
输出:
your question: ${name}
我的预期输出:
your question: How old are you?
answer: 21
1条答案
按热度按时间bvn4nwqk1#
如果希望${name}和${value}解析为变量的值,则必须使用模板文字。https://www.w3schools.com/JS//js_string_templates.asp
所以你要做的就是把'改为倒勾'
您拥有的:
应该是:
更新如下
我找不到一种方法来获取您选择的选项的文本。您可以将对象存储在一个单独的变量中,然后在执行函数中从给定的答案中搜索问题的。但这是您获取所选选项的值的方法。所有这些都在文档www.example.com中https://discordjs.guide/slash-commands/parsing-options.html#choices