[英]How do I make a dropdown help embed that changes when you select an option?
I am making a Discord bot with discord.js.我正在用 discord.js 制作 Discord 机器人。 I want to make a help menu which has a drop down.
我想做一个有下拉菜单的帮助菜单。 When a user selects an option I want the help embed to change accordingly to the option to show the list of commands for that category.
当用户选择一个选项时,我希望嵌入的帮助相应地更改为显示该类别的命令列表的选项。 Here is my code:
这是我的代码:
const{ Discord, MessageActionRow, MessageSelectMenu} =
require("discord.js")
const {MessageEmbed} = require("discord.js")
module.exports = {
config: {
name: 'help',
description: 'Get a list of all the commands',
timeout: "5000",
usage: `!ping`
},
run: async (client, message, args) => {
const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId("test") // this is the id i made in ../../events/interactionCreate
.setPlaceholder('Dropdown')
.setMinValues(1)
.setMaxValues(1)
.addOptions([
{
label:"Main" ,
description:"View our main commands.",
value:"main",
emoji:"👑" // This can also be replaced with a custom emoji
},
{
label:"Utility",
description:"View our utility commands.",
value:"utility",
emoji:"🔧" // Same as above
},
])
)
const embed = new MessageEmbed ()
.setTitle("Help")
.setDescription("Select a catagory to see a list of commands for it.")
message.channel.send({embeds: [embed], components: [row]})
}
}
You simply need to create a MessageComponentCollector
, and when a button is pressed you edit your embed.您只需要创建一个
MessageComponentCollector
,然后按下按钮即可编辑嵌入。
// we store the message in a variable to create the collector on it
const MSG = await message.channel.send({embeds: [embed], components: [row]});
// filter out bots
const filter = i => !i.user.bot;
// create the collector on your message
const collector = MSG.createMessageComponentCollector({ filter, time: 35000 });
collector.on("collect", i => {
// only allow the author to interact
if(i.member.id != message.author.id) {
return i.reply({ content: `${i.member} This Menu is not for you`, ephemeral: true})
}
// access your menu option by using i.values[index]
if(i.values[0] === "utility") {
embed.setDescription("Your new modified embed")
MSG.edit({ embeds: [embed] });
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.