0

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.

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57

0 Answers0