3
votes

How can I edit an sent embed with my bot? First I contructed an embed:

const countdownEmbed = {
color: 0x0099ff,
title:('Countdown'),
author: {
    name:`${user_name}`,
    icon_url: `${user_pfp}`,
},
description: 'Your countdown starts in **3 seconds**',
thumbnail: {
    url: `${client_pfp}`,
},
timestamp: new Date(),
footer: {
    text: `© ${client_name}`, 
    icon_url: `${client_pfp}`,
},
};

Then I made a new embed:

const countdownEmbed2 = {
    title:("New title!"),
    description: 'Your countdown starts in **2 seconds**',
};

After creating the "updated" embed I tried to send the message and then edit it after a second:

message.channel.send({ embed: countdownEmbed })
.then((msg)=> {
    setTimeout(function(){
        msg.edit(countdownEmbed2);
    }, 1000)
});

My code only sends the initial embed and does not edit it. But if I change the CountEmbed2 in msg.edit(countdownEmbed2) to a string, it will edit the message itself in Discord, but not the embed. Is there a way to fix this? Or is there an easier way to edit an embed?

2

2 Answers

2
votes

I am unsure why but after my test, I concluded that your issue is caused by the way you're writing your embeds.

if you use the MessageEmbed constructor (if you're using discord.js v11 it's RichEmbed) it'll work.

This worked while testing it out:

const countdownEmbed = new MessageEmbed()
    .setDescription('test1')

const countdownEmbed2 = new MessageEmbed()
    .setDescription('test2')
    .setColor('RED')

message.channel.send({ embed: countdownEmbed }).then((msg) => {
    setTimeout(function () {
        msg.edit(countdownEmbed2);
    }, 1000)
})
0
votes

Here is an example of an edit

const editEmbed = new Discord.MessageEmbed()
  .setDescription('this is the old description')
message.channel.send(editEmbed).then((m) => 
m.edit(editEmbed.setDescription('this is the new description')))

let me know if this worked