Search code examples
javascriptnode.jsdiscorddiscord.jscurrency

trying to make a currency system in discord.js (Balance not shop)


OK so sorry for posting "Again" but I wanna make a currency/balance system but idk how to make the system. I'm tryna explain it lol, ok so, I want to have the values save when you use b!bake command i dont really want too add a shop just something that will keep and display balance. This is my code so far

'if (message.content === prefix + "bake") {
message.channel.send("you baked" + " " + random + " " + "Cookies! :3 :cookie:")
var currency = ("Cookies") }'

If anyone can help me with this please do.


Solution

  • I do not recommend storing data inside a json file no matter the size of your project

    If youre using glitch, then I suggest quick.db. Its a wrapper for better-sqlite3 which is very very fast. It is stored inside a file inside your project and is easily accessible.

    Once you have quick.db:

    1. You can use db.fetch / db.set / db.delete / db.add / db.subtract to help you use the database

    2. Example: db.set('balance' + message.author.id, 5)

    3. Example to get balance: let balance = db.fetch('balance' + message.author.id) || 0