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

148
Views
Siempre perdiendo (Discordjs V12)

Tengo un bot en discord.js v12 e hice un código para el banco. Hice monedas al azar, pero el problema es que siempre pierdo monedas y nunca recibo/gano.

Quiero que sea para que pierdas o ganes. Aquí está mi código:

 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 answers
Answer question

0

Es porque está verificando si what variable es igual a la cadena "1" pero siempre es un número entero, por what que solo se ejecuta el bloque else . El número 1 y la cadena "1" no son lo mismo.

Asegúrese de verificar si what === 1 en su lugar y funcionará correctamente:

 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 Report
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!