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

259
Visualizações
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
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