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

128
Views
Compruebe si el usuario tiene datos para Economy Bot discord.js

Hola, estoy codificando en un Economy-System en este momento, pero tengo un problema. Tengo que comprobar si el usuario tiene datos y si no tiene datos crearlo. Esto es lo que he hecho:

 if (UserJSON.user[message.author.id]) { //It doesn't detect the message.author.id console.log("User Data already exists"); return; } else { const newUser = { user: message.author.id, stats: { money: 0 } } UserJSON.push(newUser); fs.writeFileSync("./data/users.json", JSON.stringify(UserJSON, null, 2)); }

La función de escritura de datos funciona perfectamente, como puede ver aquí abajo en users.json

 [ { "user": "654022997983756328", "stats": { "money": 0 } }, { "user": "917065319724507176", "stats": { "money": 0 } } ]

El unico problema es "comprobar si el usuario tiene datos" No detecta

 [message.author.id]

Alguien me dijo que hiciera

 if (UserJSON.[message.author.id].user) {

pero lamentablemente tampoco funcionó. ¿Alguien puede ayudarme aquí a solucionar este problema?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto se debe a que UserJSON es una matriz y está intentando acceder a la propiedad de "usuario" en la condición if, que no existe. Debe verificar si la matriz UserJSON contiene un objeto que tiene el valor de "usuario" de la condición. Prueba esto: if (UserJSON.find((userObject) => parseInt(userObject.user) === message.author.id)) { console.log("User Data already exists"); return; }

about 4 years ago · Santiago Trujillo 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!