简体   繁体   English

当您选择 select 时,如何使下拉帮助嵌入更改?

[英]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.

相关问题 如何添加一个下拉菜单,当您 select 一个选项并单击发送时,它会显示 email 中的选项? - How do I add a dropdown menu that when you select an option and click send it shows the option in the email? 如果选择了另一个选择下拉列表中的一个选项,如何显示选择下拉列表 - How do I display a select dropdown list when one option on another select dropdown is selected 选择下拉选项时如何运行一段JavaScript? - How to run a piece of javascript when you select a dropdown option? 如何使拨动开关触发 select 下拉菜单以随机化其选项值? - How do I make a toggle switch trigger a select dropdown to randomize its option value? 如何进行下拉多选? - How do I make a dropdown multi select? 选择其他字段元素时,如何重置选择选项下拉菜单? - how do i reset select option dropdown when selecting a different field element? 获取返回值[object Object]以获取第一个结果的下拉列表。 当我选择一个选项并且有效时它会改变。 如何修复默认结果 - Getting return Value [object Object] for dropdown at first result. It changes when i select an option and works. How to fix the default result 当用户单击选择标记上的提交时,如何使“选择一个”选项不通过? - How do I make the “select one” option not go through when the user clicks submit on the select tag? 如何制作选择框的下拉选项 - How to make the dropdown option of a select box 当您进入网站时,如何使下拉菜单不消失? - How do I make the dropdown menu not being down when you enter the website?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM