How would I "refresh" a discord embed on discord.js? More info down vv

Viewed 877

I am coding a bot on discord.js, and I was wondering how I could make this so that the embed would refresh after the button is pressed? What should happen is the embed's enemyamt value would be changed, however it does not refresh. It actually does change the value though, as shown through button.channel.send(enemyamt); I was thinking it can be done in one (or more) of these ways:

  1. Have it be refreshed. Apparently it is through message.edit() ? I do not know.
  2. Have the message be deleted and then resent, updated.

I have the code below, only snippets of it however since I do not want it to take up too much space. And yes, I know it doesn't look the best lol. Thank you in advance :)

    if (button.id === 'charge') {
        enemyamt = 75;
        button.channel.send(enemyamt);
    }
    if (button.id === 'rally') {
        //button.channel.send('Vive le Roy');
        //enemyamt = 75;
    }
})

client.on('message', message => {
    if (message.content === '!battle') {
        let embed = new Discord.MessageEmbed()
            .setColor('#318CE7')
            .setTitle('Battle')
            .addField('<:rebel:852380749242957824> Rebel Forces', enemyamt + ' hussars\nMorale: ' + enemymor + '%', true)
            .addField('<:HKPL:852380579248341022> HKPL Forces', homeamt + ' hussars\nMorale: ' + homemor + '%', true)
            .setImage('https://media.discordapp.net/attachments/798525635215360003/852027255336599552/unknown.jpeg')
            .setFooter('Niech żyje król')
        
        let btn1 = new disbut.MessageButton()
            .setStyle('red')
            .setLabel('⚔️ Charge')
            .setID('charge')
            //.setDisabled()

        let btn2 = new disbut.MessageButton()
            .setStyle('red')
            .setLabel(' Rally')
            .setID('rally')
            //.setDisabled()

        message.channel.send({ buttons: [btn1, btn2], embed: embed})
    }
})```


1 Answers

The .send method also is a Promise and the callback is the message handle, so you can just take this handle and use the .edit method on it

message.channel.send("My Initial Message").then(msg => {
    msg.edit("My edited Message");
});
Related