Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS Check if user has a data for Economy Bot discord.js

Elektrodemon

New Coder
Heyo, I'm coding on an Economy-System right now but I have a problem.
I have to check if the user has data and if he doesn't have data create it.
Here is what I've done:

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)); }

The writing data function works perfectly as you can see down here in the users.json

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

The only problem is "check if the user has data"
It doesn't detect

[message.author.id]
Someone told me to do

if (UserJSON.[message.author.id].user) {
but sadly it didn't work too.
Can anyone help me here fix this issue?
 

Latest posts

Buy us a coffee!

Back
Top Bottom