how to detect an embed and then resend it

i want to do if the bot received the bot embed title call "wild pokémon has appeared!" then it will send message.
11 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
lupus
lupus2y ago
You could listen to messageCreate, check the embed property and then check if the title of the (first) embed matches. (See KAVI's message below)
KAVI
KAVI2y ago
<Message>.embeds gives you access to the embed array. Check it's length to see if there are any embeds, if not ignore the message. And by using <Message>.embeds[0].title you can get the title of the first embed in that message. Combine the two instructions <:T_wink:940369475503530004>
lupus
lupus2y ago
:D
CoolName
CoolNameOP2y ago
so the code will be
if (message.embeds[0].title === '')
if (message.embeds[0].title === '')
?
KAVI
KAVI2y ago
Something like that yeah. But remember. Like I said. The 0th index of the array could be null at some point. It's good practice to check that before you check the title. But if you're certain that there will be an embed... then yes My advice is to scope it to a channel Rather than the whole messageCreate event
lupus
lupus2y ago
Or use optional chaining for that to prevent sudden errors (?.)
KAVI
KAVI2y ago
Oh yeah... that as well.. lmao forgot about that for a second there thanks
CoolName
CoolNameOP2y ago
thanks man thanks man it worked
lupus
lupus2y ago
You’re welcome
KAVI
KAVI2y ago
Another happy coder. Keep up the good work <:nb_cat_pat:851511871664029707>
Want results from more Discord servers?
Add your server