Can a Discord bot detect keywords in embed messages?

Hey everyone! I'm new to Discord bot development and I'm stuck on something. I know how to make my bot respond to regular messages using a simple if statement. Like this:

if (msg.content.toLowerCase().includes('hello')) {
    msg.reply('Hi there!');
}

But I can't figure out how to make it work with embed messages. Is there a way to check for keywords in embeds and get the bot to respond? I've tried a few things but nothing seems to work. Any tips or code examples would be super helpful! Thanks in advance!

yo, i had a similar issue. what worked 4 me was checkin the embed.description property. it’s where most of the text usually goes. try somethin like:

if (message.embeds[0] && message.embeds[0].description.toLowerCase().includes(‘keyword’)) {
// do stuff
}

Hope that helps bro!

Detecting keywords in embed messages is more challenging than checking plain text because you have to manually extract the different parts of an embed. In my experience, you need to first determine whether the message has any embeds. Once confirmed, you should iterate through each embed and concatenate its title, description, and any field values into one composite string. After combining these elements, you can perform a case-insensitive search for your keyword within that string. This approach helps manage the structure of embed messages and ensures that no keyword goes unnoticed.

I’ve actually dealt with this exact issue in one of my Discord bots. It’s not as straightforward as checking regular messages, but it’s definitely doable. What worked for me was accessing the embed properties through the message object. You’ll want to check message.embeds to see if there are any embeds, then loop through them. Each embed has properties like title, description, and fields that you can search for keywords.

Here’s a rough example of how I approached it:

if (message.embeds.length > 0) {
  message.embeds.forEach(embed => {
    let embedContent = embed.title + ' ' + embed.description;
    embed.fields.forEach(field => {
      embedContent += ' ' + field.name + ' ' + field.value;
    });
    
    if (embedContent.toLowerCase().includes('your_keyword')) {
      // Respond to the keyword
    }
  });
}

This method has worked well for me in catching keywords across different parts of embed messages. Hope this helps!