How do you search for an embed in discord.js

tpoodle1

I am attempting to make a simple starboard system on discord.js, and the deleting a message part is stumping me. Currently, if a message gets a star, an embed is created in a starboard channel, and, critically, the footer is the original message's id. I want to make the inverse function (when the star is removed, the embed is deleted) work by finding the embed with that footer and then deleting that embed, but it's not working for some reason. The error I keep getting is "UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'cache' of undefined." How do I property define this variable?

  if (reaction.emoji.name === `⭐`) {
    const guild = reaction.message.guild;
    await reaction.fetch();
    const stars = reaction.count;
    if (stars === 0) {
      const embed = guild.messageEmbed.cache.find(embed => embed.footer === reaction.message.id);
      embed.delete
    }
  }
}
mswgen

You have to find the embed from the starboard channel, not from the entire guild. You can use Channel.messages.fetch and Channel.messages.cache.find to find a specific message. Try this:

if (reaction.emoji.name === `⭐`) {
    const guild = reaction.message.guild;
    await reaction.fetch();
    const stars = reaction.count;
    if (stars === 0) {
      guild.channels.cache.get('starboard-channel-id').messages.fetch().then(fetchedMsgs => {
        fetchedMsgs.find(x => x.embeds[0].footer.text == reaction.message.id).delete();
      })
    }
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do you make it so there is an introduction embed in discord.py?

Google Maps: How do you embed it WITH search bar?

How do I reset Embed data in discord.js?

How do I make an embed in discord?

How to ping a role in a discord.js embed

How do you catch an error in this timer code for discord.js?

How do you shift an arg twice in Discord.js

How do you give a specific member a role? Discord.js

How do you use arguments with multiple words in discord.js?

How do you pass a string as an option in Discord.js

Discord JS - How do you get the status of a user within a Guild?

Discord.js - how do I edit message.embed() statements?

Discord.js How do i make an embed goes to a specific channel

How do I send an embed with buttons to a specific channel in discord.js?

How do you embed binary data in XML?

How do you embed an iframe into markdown

How do you get the value of a "embed"?

How do you attach local files to an embed?

How do I search for an element in a JS object (building a Discord Bot - discord.js)

React.js: How do you implement search functionality?

Discord JS Embed reaction to lead to another embed

How do you search with TransactionSearch?

How do you search by Id?

How do I fetch text from discord web block embed

How do I put discord.py help command in an embed?

Python Discord Bot | How do I mention someone in embed?

How do I make the Discord bot reply in "Embed" form in TypeScript

How do I mention a user with the blue highlight in Discord Embed?

How to get the message link of an embed in discord.js?