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

151
Visualizações
I want my embed colour to be set between 2 different colours

So currently, I have a piece of code which chooses yellow to set as the colour of the embed.

.setColor('YELLOW')

This works fine and sets the colour of the embed to yellow. With my limited knowledge of js, I figured that adding || which is the logical OR operator, it would allow the bot to choose between either yellow or another colour. So I changed the code to this:

.setColor('YELLOW' || 'RED')

When I tested this code, it didn't work. It just kept the colour to yellow. I tried saving the file multiple times. I also allowed the bot to go offline and then retired it, to no avail. Could someone help me out, please?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The OR (||) operator always returns the first truthy value, YELLOW in your case.

If you only want to choose between those two, you can put them in an array and use Math.random() to generate a random number. If this number is less than 0.5, you can choose the first one, if it's larger, choose the second one:

console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])
console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])
console.log(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])

You can update your code like this:

.setColor(['YELLOW', 'RED'][Math.random() < 0.5 ? 0 : 1])
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