• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

158
Vistas
only works if the content of author.name is exact or leftover words

The bot reacts only when the content of author.name is exact, but if it has an extra word it doesn't work, but it doesn't throw an error example:

const ListClaims = ["rick sanchez", "alex", "juan"];

rick sanchez has no error because it is exact to ListClaims

rick sanchez morty has an error because it has additional letters which is morty,

    var ListClaims = ["rick sanchez","alex","juan"];

    if(message.embeds.length >= 0) 
    // Check if the Message has embed or not
    {
      let embed = message.embeds
      // console.log(embed) just a console.log
      for(let i = 0; i < embed.length; i++)
      {
        if (!embed[i] || !embed[i].author || embed[i].author.name === null) return;
        // check each embed if it has setAuthor or not, if it doesnt then do nothing
        {
        if(embed[i].author.name.toLowerCase().includes(ListClaims))
        // check each embed if it includes word
        {
          message.react('🎉')
        }
        }
      }
    }
almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've reformated your code, so it's simpler and easier to read. If you give a better example of what you want to happen, I can edit this answer to solve it better.

function messageHandler() {

  const msg = {
    embeds: [
      { author: { name: "alex" }},
      { author: { name: "john"}},
      { author: { name: "rick sanchez morty"}},
    ]
  }

  const listClaims = ["rick sanchez", "alex", "juan"];

  // 0 is falsey by default, so you dont have to check if it's  == 0.
  if (!msg.embeds.length) return;
  // Check if the Message has embed or not

  msg.embeds.forEach(embed => {
    // "", null and undefined are also falsey, so we don't need to check them.
    // also this if statement is not needed, since you can just do Array.includes().
    if (!embed.author.name) return;

    // .includes() is an array method, not a string method, so you have to do Array.includes(target), not target.includes(array).
    if (listClaims.includes(embed.author.name.toLowerCase())) message.react('🎉');
  });
}

const message = {
  react: console.log
};

messageHandler()

almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda