Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
Discord Button failed Pop up on command

I am trying to make a Menu for my Discord server and I've got the slash command working, but with I go to pull the menu I get: Main menu as a return in discord when executing the slash command.

I used the following code to get as far as I have:

    //Remember to run " node deploy-commands.js " to register your commands!

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageActionRow, MessageButton } = require('discord.js');


module.exports = {
    data: new SlashCommandBuilder()
        .setName('menu')
        .setDescription('Brings up the Main Menu'),
    async execute(interaction, client) {
        const row = new MessageActionRow()
                        .addComponents(
                                new MessageButton()
                                        .setCustomId('dice-bag')
                                        .setLabel('danger')
                                        .setStyle("DANGER"),
                                
                                new MessageButton()
                                        .setCustomId('spells')
                                        .setLabel('primary')
                                        .setStyle("PRIMARY"),
                                        
                                new MessageButton()
                                        .setCustomId('inventory')
                                        .setLabel('Success')
                                        .setStyle("SUCCESS"),
                        );
                        await interaction.reply({content: 'Main menu,', components: [row]})
    },
};

I have a feeling I need to embed the message somehow but am not 100% sure how. I'm pretty sure that I need to likely add something the:

await interaction.reply({content: 'Main menu,', components: [row]})

I'm pretty sure the components: [row]}) is wrong but I'm not sure what to put in its place. anytime I try to fix it I get errors about MessageActionRow action row needing NEW.

Thank you for any help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Note! This is assuming you are using Discord.js v13.2.0.


According to the documentation, <MessageActionRow>.addComponents(...) expects an Array of MessageActionRowComponentResolveables. This look something like this:

<MessageActionRow>.addComponents([
new MessageButton().setValue("option1").setStyle("PRIMARY"),
new MessageButton().setValue("option2").setStyle("DANGER")
]);

The important thing to note here is the usage of braces ([]). In JavaScript, braces indicate an Array. In your code, you are missing the braces.

// DON'T do this!
<MessageActionRow>.addComponents(new MessageButton, new MessageButton);

// DO this!
<MessageActionRow>.addComponents([ new MessageButton, new MessageButton ]);

With that, your code isn't too different. All you have to do is add the braces.

<MessageActionRow>.addComponents([
new MessageButton()
.setCustomId('dice-bag')
.setLabel('danger')
.setStyle("DANGER"),

new MessageButton()
.setCustomId('spells')
.setLabel('primary')
.setStyle("PRIMARY"),
                                        
new MessageButton()
.setCustomId('inventory')
.setLabel('Success')
.setStyle("SUCCESS")
]);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda