Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit an embed with your bot Discord.js?

Tags:

discord.js

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?

like image 909
EeveeEmma Avatar asked Jan 20 '26 15:01

EeveeEmma


1 Answers

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)
})
like image 181
Syntle Avatar answered Jan 22 '26 03:01

Syntle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!