Skip to content
Advertisement

Remove 1 element from Embed object DiscordJS

I have been trying to code a bot that copies 1 embed from 1 channel to another channel.

But what I want it to do before posting it to the other channel, I want it to remove 1 element from the embed object.

How I have it currently:

client.on("message", (message) => {
    if (message.channel.id == channel1) {
        const embed = message.embeds[0];
    
        var params = {
            embeds: ,
        };
    
        fetch("WEBHOOK URL", {
            //send channel 2
            method: "POST",
            headers: {
                "Content-type": "application/json",
            },
            body: JSON.stringify(params),
        }).then((res) => {});
    }
});

As you can see i straight use message.embeds[0].

So i don’t even know if it possible to remove 1 element from it like the footer text for example.

If anyone knows if it can be done or not, please say so.

Thank you for reading.

EDIT:

Would it be something like:

const embed = message.embeds[0];

embed.footer.text = [];
// or
embed.footer[0].text

Advertisement

Answer

You can use the delete operator to remove a property from an object.

const embed = message.embeds[0];
if (!embed) return;

delete embed.footer;

message.channel.send({
    content: "Footer removed!",
    embeds: 
});

Note that you can’t remove only the text property and keep the icon. The footer won’t show without a text property.

enter image description here

These work too:

// Remove only text from footer (footer won't be visible including icon)
embed.footer.text = "";
// Or
embed.footer = {};
// Or
embed.footer = null;
// Or ...
Advertisement