YourDailyRegularWeeb
YourDailyRegularWeeb

Reputation: 23

Discord JS - Embed Footer Text

I'm trying to make a starboard so here is my code:

const starChannel = bot.channels.cache.find(channel => channel.name.toLowerCase() === 'test-logs');
const fetchedMessages = await starChannel.messages.fetch({ limit: 100 });
const stars = fetchedMessages.filter((m) => m.embeds.length != 0).find((m) => m.embeds[0].footer.text.includes(message.id));
const image = message.attachment.size > 0 ? await(reaction, message.attachment.array()[0].url) : '';

const embed = new Discord.MessageEmbed()
  .setAuthor(message.author.tag, message.author.displayAvatarURL({ format: 'png', dynamic: true }))
  .setDescription(message.content)
  .addField("Original:", `[**Jump to message**](https://discordapp.com/channels/${message.guild.id}/${message.channel.id}/${message.id})`)
  .setFooter(`Message ID: ${message.id}`)
  .setTimestamp()

Then I got this rejection error: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'text' of undefined

Upvotes: 1

Views: 7424

Answers (1)

Cipher
Cipher

Reputation: 2722

embed.footer can be null, so you need check if embed has footer.

Like this

const fetchedMessages = await starChannel.messages.fetch({ limit: 100 });
const stars = fetchedMessages.filter((m) => m.embeds.length != 0).find((m) => m.embeds[0].footer && m.embeds[0].footer.text.includes(message.id));
const image = message.attachment.size > 0 ? await (reaction, message.attachment.array()[0].url) : '';

const embed = new Discord.MessageEmbed()
    .setAuthor(message.author.tag, message.author.displayAvatarURL({ format: 'png', dynamic: true }))
    .setDescription(message.content)
    .addField("Original:", `[**Jump to message**](https://discordapp.com/channels/${message.guild.id}/${message.channel.id}/${message.id})`)
    .setFooter(`Message ID: ${message.id}`)
    .setTimestamp()

Upvotes: 1

Related Questions