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

250
Views
Import config with number as name

I'm building a Discord bot (.js V12). I am now building a color command. Usage: $color idhere. The problem that I just encountered, is that I build my list like this:

exports.coloridlist = {
    1: "white",
    2: "grey",
    3: "etc",
}

When I try to import a value, it gives me an error, because of the numbers. Sample of my code:

    if (coloridlist.1 == args[0]) { // Problem here, coloridlist.1
      console.log(`${message.author.username} now has a new role color: ${args[0]}.`)
      .get(user.id)
      .roles.add(whiteTeamRole);
      message.channel.send(`You now have new rolecolor: <@roleidhere>.`)
    } else if (coloridlist.2 == args[0]) { // Problem here
      console.log(`${message.author.username} now has a new role color: ${args[0]}.`)
      .get(user.id)
      .roles.add(greyTeamRole);
      message.channel.send(`You now have new rolecolor: <@roleidhere>.`)
    } else if //etc

It would be easy for the user to just do $color 1 (where 1 is the color id), since the string is vulnerable for type errors, and just not quick.

So does anyone know how I can work around this? Since I am working with 200+ colors with this sytem, it would be nice if I can fix this.

about 4 years ago · Juan Pablo Isaza
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!