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!
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")
]);