Search code examples
discord.jsdiscord-buttons

Edit an embed on ButtonClick discord.js


I have tried making a command menu embed with buttons to go through pages. The only problem with this is you can't edit the bot message (I believe), since you can only use listeners for the button like this:

bot.on('clickButton', (button) => {
   if (button.id === 'someid') {
      button...
   }
})

... So how exactly could you edit an embed?


Solution

  • You can edit the bot's message which has buttons attached to it. The button is an instance of MessageComponent. Which has a .message property you can use to access the original message the button was attached to.

    const message = button.message;
    const embed = new Discord.MessageEmbed();
    // ... Set embed properties ...
    message.edit(embed);
    

    If you want to edit a reply to an interaction that was sent by the bot, use InteractionReply.edit() method.

    button.reply.edit(embed);