Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!