[英]how to chose a choice of a subcommand- dJS v13
I've been looking for a solution for days and I can't seem to find one.几天来我一直在寻找解决方案,但似乎找不到。 I want to have multiple subcommands (3) and be able to choose an option and then a choice.
我想要多个子命令 (3) 并且能够选择一个选项,然后再进行选择。 I know how to respond to an option but I can't seem to respond to a choice after that.
我知道如何回应一个选项,但在那之后我似乎无法回应一个选择。 Someone, please help me out I would really appreciate it so much!
有人,请帮助我,我将非常感激! - thank you in advance!
- 先感谢您! (sry if that's confusing)
(对不起,如果这令人困惑)
like this /find crystal(subcommand) search(option):<choice>
||像这样
/find crystal(subcommand) search(option):<choice>
|| example: /find crystal search:random
示例:
/find crystal search:random
i want it to work like his enter image description here我希望它像他在此处输入图像描述一样工作
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 :/"});
}
}
}
};
Its simple.这很简单。 You normally do
interaction.options.getString('search');
你通常会做
interaction.options.getString('search');
It will give you the value and you don't need to do .value
.它会给你价值,你不需要做
.value
。 Like for your example where you have chosen random
it will give color_Random
.就像您选择
random
的示例一样,它将给出color_Random
。 The first name part of the choice is only for the users to see and use.选择的名字部分仅供用户查看和使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.