Home > Back-end >  discord.js - How to read data from embed
discord.js - How to read data from embed

Time:12-21

I'm trying to get color of the embed in message. That message has an embed (with color), but it still says false in log.

let messageId = '922497690359716898';

if(messageId.embeds){
    let applicationAuthor = messageId.embeds.color;

    console.log(applicationAuthor)
} else console.log('false');

CodePudding user response:

A single ID/snowflake doesn't have an embeds property. You need to fetch the message by this ID first and check its embeds once it's resolved.

If the message with the embed is in the same channel as the message with the command, you can use this:

let messageId = '922497690359716898';
try {
  let messageWithEmbed = await msg.channel.messages.fetch(messageId);
  if (messageWithEmbed.embeds?.[0]) {
    let color = messageWithEmbed.embeds[0].color;
    console.log(color);
  } else {
    console.log('no embed found')
  }
} catch (err) {
  console.log(err);
}
  • Related