const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('button-test') .setDescription("Button test command."), async execute(interaction) { let e = new EmbedBuilder() .setDescription(`Click buttons!`) .setColor("Random"); let b = new ActionRowBuilder().addComponents( new ButtonBuilder() .setLabel('Button 1') .setCustomId(`b1`) .setStyle(ButtonStyle.Success), new ButtonBuilder() .setLabel('Button 2') .setCustomId(`b2`) .setStyle(ButtonStyle.Primary)); let msg = await interaction.reply({ embeds: [e], components: [b] }); const collector = msg.createMessageComponentCollector() collector.on('collect', async (i) => { if (i.customId === `b1`) { if (i.user.id !== interaction.user.id) { let nope = new EmbedBuilder() .setDescription(":x: You cannot use these buttons!") .setColor('#ff0000'); return i.reply({ embeds: [nope], ephemeral: true }); } else { await i.deferUpdate(); let e2 = new EmbedBuilder() .setDescription('Button 1 was clicked.') .setColor("Random"); let back = new ActionRowBuilder().addComponents( new ButtonBuilder() .setLabel('Back') .setCustomId(`back`) .setStyle(ButtonStyle.Secondary)); await i.editReply({ embeds: [e2], components: [back] }); } } else if (i.customId === `b2`) { if (i.user.id !== interaction.user.id) { let nope2 = new EmbedBuilder() .setDescription(":x: You cannot use these buttons!") .setColor('#ff0000'); return i.reply({ embeds: [nope2], ephemeral: true }); } else { await i.deferUpdate(); let e3 = new EmbedBuilder() .setDescription('Button 2 was clicked.') .setColor("Random"); let back2 = new ActionRowBuilder().addComponents( new ButtonBuilder() .setLabel('Back') .setCustomId(`back`) .setStyle(ButtonStyle.Secondary)); await i.editReply({ embeds: [e3], components: [back2] }); } } else if (i.customId === `back`) { if (i.user.id !== interaction.user.id) { let nope3 = new EmbedBuilder() .setDescription(":x: You cannot use this button!") .setColor('#ff0000'); return i.reply({ embeds: [nope3], ephemeral: true }); } else { await i.deferUpdate(); let e4 = new EmbedBuilder() .setDescription(`Click buttons!`) .setColor("Random"); let b2 = new ActionRowBuilder().addComponents( new ButtonBuilder() .setLabel('Button 1') .setCustomId(`b1`) .setStyle(ButtonStyle.Success), new ButtonBuilder() .setLabel('Button 2') .setCustomId(`b2`) .setStyle(ButtonStyle.Primary)); await i.editReply({ embeds: [e4], components: [b2] }); } } }); }, };