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 toolkit12mo 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
lupus12mo 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
KAVI12mo 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
lupus12mo ago
:D
CoolName
CoolName12mo ago
so the code will be
if (message.embeds[0].title === '')
if (message.embeds[0].title === '')
?
KAVI
KAVI12mo 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
lupus12mo ago
Or use optional chaining for that to prevent sudden errors (?.)
KAVI
KAVI12mo ago
Oh yeah... that as well.. lmao forgot about that for a second there thanks
CoolName
CoolName12mo ago
thanks man thanks man it worked
lupus
lupus12mo ago
You’re welcome
KAVI
KAVI12mo ago
Another happy coder. Keep up the good work <:nb_cat_pat:851511871664029707>