Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
Always losing (Discordjs V12)

I have a bot in discord.js v12 and I made a piece of code for the bank. I made random coins but the problem is that I always lose coins and never receive/gain.

I want to make it so you lost or gain. Here is my code:

if (message.content === '.randomcoins') {
  let currentBalance = await db.get(`wallet_${message.author.id}`);
  let randomc = Math.floor(Math.random() * 100 + 1);
  var what = Math.floor(Math.random() * 2 + 1);
  if (what === '1') {
    await db.set(`wallet_${message.author.id}`, currentBalance + randomc);
    message.channel.send(`You recived ${randomc} Coins.`);
  } else {
    await db.set(`wallet_${message.author.id}`, currentBalance - randomc);
    message.channel.send(`You lost ${randomc} Coins.`);
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's because you're checking if the variable what is equal to the string "1" but what is always an integer so only the else block runs. The number 1 and the string "1" is not the same thing.

Make sure you check if what === 1 instead and it will work properly:

if (message.content === '.randomcoins') {
  let currentBalance = await db.get(`wallet_${message.author.id}`);
  let randomc = Math.floor(Math.random() * 100 + 1);
  var what = Math.floor(Math.random() * 2 + 1);
  if (what === 1) {
    await db.set(`wallet_${message.author.id}`, currentBalance + randomc);
    message.channel.send(`You recived ${randomc} Coins.`);
  } else {
    await db.set(`wallet_${message.author.id}`, currentBalance - randomc);
    message.channel.send(`You lost ${randomc} Coins.`);
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda