[英]how to chose a choice of a subcommand- dJS v13
幾天來我一直在尋找解決方案,但似乎找不到。 我想要多個子命令 (3) 並且能夠選擇一個選項,然后再進行選擇。 我知道如何回應一個選項,但在那之后我似乎無法回應一個選擇。 有人,請幫助我,我將非常感激! - 先感謝您! (對不起,如果這令人困惑)
像這樣/find crystal(subcommand) search(option):<choice>
|| 示例: /find crystal search:random
我希望它像他在此處輸入圖像描述一樣工作
const { Client, MessageEmbed, CommandInteraction } = require("discord.js");
module.exports = {
name: "find",
description: "search from crystals to herbs and colors!",
options: [
{
name: "crystal",
description: "sends a specific or random crystal from datebase",
type: 1, // 1 is type SUB_COMMAND
options: [
{
name: "search",
description: "specify what crystal you want to search",
type: 3, // 3 is type STRING
required: true,
choices: [
{
name: "random",
value: "crystal_random",
},
{
name: "clearquartz",
value: "crystal_clearQuartz",
},
]
},
]
},
{
name: "herb",
description: "sends a specific or random herb from datebase",
type: 1,
options: [
{
name: "search",
description: "specify what herb you want to search",
type: 3,
required: true,
choices: [
{
name: "random",
value: "herb_Random",
},
{
name: "aloe",
value: "herb_aloe",
},
]
},
]
},
{
name: "color",
description: "sends a specific or random color from datebase",
type: 1,
options: [
{
name: "search",
description: "specify what color you want to search",
type: 3,
required: true,
choices: [
{
name: "random",
value: "color_Random",
},
{
name: "red",
value: "color_red",
},
]
},
]
}
],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {String[]} args
*/
run: async (client, interaction, args) => {
const [ message ] = args;
const color = '#EEB8B6';
//--------------------------------------------------------------------------------------------------------------------------------------------------------
let CrystalsJason = require('../../scripts/crystals.json');
let AllCrystals = [ CrystalsJason.crystals.clearQuartz, CrystalsJason.crystals.agate, CrystalsJason.crystals.amethyst, CrystalsJason.crystals.aquamarine, CrystalsJason.crystals.blackTourmaline, CrystalsJason.crystals.carnelian, CrystalsJason.crystals.citrine];
let crystalOutcome = AllCrystals[Math.floor(Math.random() * AllCrystals.length)];
const randCrystal = new MessageEmbed()
.setTitle(`<:crystalmoon:911423663306338355> Crystal: ${crystalOutcome.name} <:crystalmoon:911423663306338355>`)
.addField(`Properties: `, `${crystalOutcome.properties}`, true)
.addField("Fact: ", `${crystalOutcome.fact}, `, true)
.setColor(color)
.setThumbnail(crystalOutcome.image)
.setFooter(`${crystalOutcome.foot}`)
if (interaction.options.getSubcommand() === "crystal" ) {
const search = interaction.options.getString("search");
const random = interaction.options.getString("crystal_random").value
if(search && random){
return interaction.followUp({embeds: [randCrystal]});
}
else {
return interaction.followUp({content: "didnt work :/"});
}
}
}
};
這很簡單。 你通常會做interaction.options.getString('search');
它會給你價值,你不需要做.value
。 就像您選擇random
的示例一樣,它將給出color_Random
。 選擇的名字部分僅供用戶查看和使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.