Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
my array stops working if I put more than 2 values

if an insert has one of ListClaims names in .setAuthor it reacts with an emoji, that's what I want it to do, but it stops working if I put more than 1 name in ListClaims, try to use a txt but it doesn't work.

    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].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('🎉')
        }
        }
      }
    }
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You are calling includes() in a string (author.name) with an array argument. You want to run it the other way around. So instead of:

if (embed[i].author.name.toLowerCase().includes(ListClaims))

Try using:

if (ListClaims.includes(embed[i].author.name.toLowerCase()))
about 4 years ago · Juan Pablo Isaza Relatório

0

the js includes function can reference here

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes

the following is the sample

const array1 = [1, 2, 3];
document.write("Is array1 contain 2 : ");
document.write(array1.includes(2));

document.write("<br>");

document.write("Is array1 contain 4 : ");
document.write(array1.includes(4));

about 4 years ago · Juan Pablo Isaza Relatório

0

.includes is an array method, but youve used it as a string method.

Below I've fixed it while also cleaning up your code. The new code is in the messageHandler function.

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

// dummy message object
const msg = {
  embeds: [
    {name: "alex"},
    {name: null},
    {name: "juan"},
  ],
  react: (str) => console.log(str),
}

function handleMessage(msg){
  if (!msg.embeds.length) return;
  msg.embeds.forEach(embed => {
    if (listClaims.includes(embed.name)) msg.react('🎉');
  })
}

handleMessage(msg)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda