![](/img/trans.png)
[英]discord.js v13 is there a way to add choices in slash command numbers option?
[英]discord.js v13 - Add option to choice
我想在斜杠命令中选择使用选项。 让我解释:
/信息用户
用户编写此斜杠命令。 “用户”是此命令中的选择。 如果我们写“用户”作为选择,它应该给用户一个选项。 喜欢:
/信息服务器
如果我们这样写,它只会执行命令,因为服务器不再需要信息。
/信息用户
但是如果我们这样写,它会要求一个用户。 您可以通过编写.addUserOption
添加用户选项,但我应该将其添加到选择中,我不知道该怎么做。 这是我的代码:
const { SlashCommandBuilder } = require("@discordjs/builders")
module.exports = {
data: new SlashCommandBuilder()
.setName("info")
.setDescription("Get info about X! (usage: /info X)")
.addStringOption((o) =>
o
.setName("choice")
.setDescription("What info do you want to get?")
.setRequired(true)
.addChoice('Server', 'server')
.addChoice('User', 'user')
.addUserOption((o) =>
o
.setName("user")
.setDescription("What user do you want to get info about?")
.setRequired(true)
)
.addChoice('Bot', 'bot')
),
async execute(i) {
if (i.options.getString("choice") == 'server') {
i.reply({
content: `server`,
emphemeral: true
})
}
if (i.options.getString("choice") == 'user') {
i.reply({
content: `user`,
emphemeral: true
})
}
if (i.options.getString("choice") == 'bot') {
i.reply({
content: `bot`,
emphemeral: true
})
}
}
}
那就是我试过的。 它给了我一个错误。 我该怎么做? 谢谢。
.addStringOption()
有自己的选择。 在.addStringOption()
之后,取消缩进,使其位于开始的同一行,然后使用自己的选择添加.addUserOption()
。
// ...
.addStringOption(() => {
// ...
})
.addChoice("Foo", "foo")
.addChoice("Bar", "bar")
.addUserOption(() => {
// ...
})
.addChoice("<@1234567890>")
.addChoice("<@1234567890>")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.