Sprocx
Sprocx

Reputation: 87

I am trying to fetch the content of an embed

At the moment, I am trying to make a FAQ embed but I am trying to make a command so you can add a FAQ Question and answer. At the moment I have this code:

if (message.member.hasPermission("MANAGE_SERVER")) {
    let m1 = await message.channel.send("What is the title of the FAQ?");
    const filter = (m) => m.author.id === message.author.id;
    message.channel.awaitMessages(filter, { max: 1, time: false }).then(async (collected) => {
        const msg2 = collected.first();
        if (msg2.content.toLowerCase() === `cancel`) {
            m1.edit("Cancelled");
        } else {
            msg2.delete();
            let m2 = await m1.edit("What do you want the description of the FAQ to be?");
            const filter2 = (m) => m.author.id === message.author.id;
            message.channel.awaitMessages(filter2, { max: 1, time: false }).then(async (collected) => {
                const msg3 = collected.first();
                if (msg3.content.toLowerCase() === `cancel`) {
                    m2.edit("Cancelled");
                } else {
                    msg3.delete();

                    bot.channels.cache
                        .get("804492953388974080")
                        .messages.fetch("815234402098741259")
                        .then((msg) => {
                            let WM = new Discord.MessageEmbed()
                                .setDescription(
                                    msg.content +
                                        `**` +
                                        msg2.content +
                                        `** = ` +
                                        msg3.content +
                                        `
`
                                )
                                .setColor("BLUE");
                            msg.edit(WM);
                            m2.edit("Sent");
                        });

                    message.delete();
                }
            });
        }
    });
}

The msg declared is the embed that has already been sent. At the moment msg is empty. How can I fetch information from the description and title of the embed?

Upvotes: 1

Views: 96

Answers (1)

Itamar S
Itamar S

Reputation: 1565

Message#embeds

The embeds property of the Message object returns an array of all of the embeds inside of it, and the data they store. Knowing this, you could fetch a message in the requested channel, and receive all of the embeds it stores using the above property. We could then get the embed at index 0, and fetch the data from there.

Quick Example

const msg = await message.channel.messages.fetch('ID here');
console.log(msg.embeds[0].description) // Here we log the content of the description of the embed at index 0.
//                     ^ refers to the first embed sent

P.S: Keep in mind, I couldn't exactly figure out where you were trying to find embed data from. Please make sure you fetch the correct message using your message / channel parameter.

Upvotes: 1

Related Questions