Search code examples
javascriptdiscordembed

How to get my discord bot to respond to a keyword in the field embed of another message


So I am new to writing anything really, but I have been trying to operate a bot that pings a certain role when there is a raid spawned by another bot. I was able to have the process work for detecting the title in the message embed searching for a generic keyword of "Raid" which is great. But when I try to detect the pokemon's name of what raid it is(the other bot is Pokeverse by the way) which is located in a field value I can't seem to get anything to detect that keyword and send a message to ping a certain role.

This is what I have that works for pinging when there is a raid and Raid is detected in the title of the embed message. But I can't get it to work for the specified name as with "Regice" in the example below. I have tried looking for information on what to use instead of embed.title.includes, and trying something like embed.fields[0].includes with no luck.

If someone can help or point me in the right direction I would really appreciate it. If I need to add more information to my post also let me know. I also attached a screenshot of what the embedded message looks like from the other bot. Sorry for the messy code also.

require("dotenv").config()
const Discord = require("discord.js")
const client = new Discord.Client()
client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`)
})
client.on("message", (msg) => {
  if (msg.content === "ping") {
    msg.reply("Pong!")
  }
})

client.on('message', (message) => {
  if (message.author.id === '432616859263827988') {
    if (message.embeds.length == 1) {
      const embed = message.embeds[0]
      if (embed.title.includes("Raid")) {
        return  message.channel.send('<@&775396443833106453> Raid Time!')
      }
    }
  }
})

client.on('message', (message) => {
  if (message.author.id === '432616859263827988') {
    if (message.embeds.length == 1) {
      const embed = message.embeds[0]
      if (embed.title.includes("Swampert")) {
        return  message.channel.send('<@&775395107146039316> Raid Time!')
      }
    }
  }
})

Embed Message Example


Solution

  • use embed.fields[0].value.includes