Hello, I have recently made a coins system for my project sunshrine-kiwibot and I need assistance. I am using module FS and a JSON file called coins.json. Everytime a user gets coins, I have to refresh the project so that it saves the new coins. Are there any alternatives or solutions instead of refreshing ever time?
use json.stringify
to save without refreshing
I did do a json.stringify
:
fs.writeFile("./coins.json", JSON.stringify(coins), (err) => { if (err) console.log(err) })
Alright, well just so you know the database adapter I linked is super easy if you check out the npm page. Can you share some code of how you’re doing it right now so we can help more?
Maybe you might enjoy reading ~hello-sqlite, and imagine that you’re storing and retreiving coins instead of storing and retreiving dreams?
Mabye something like this?
UPDATE "economy"
SET coins = coins - 1
WHERE name = ?;
Johnicholas
1 Like
here: `module.exports = {
name: ‘event’,
run: async (client, message, args) => {
const { MessageEmbed } = require('discord.js')
const settings = require('../../settings.json')
message.delete()
if (!settings.owners.includes(message.author.id)) return message.reply('you don\'t have permission to use this command...').then(m => m.delete({ "timeout": 1500 }))
const fs = require('fs');
const coins = require(’…/…/coins.json’)
let randomNum = Math.floor(Math.random() * 1000000)
const { generateKey } = require('../../functions.js')
let key = generateKey()
let number = `${randomNum}`
const event = new MessageEmbed()
.setColor('GREEN')
.setTitle('Hourly coins event!')
.setDescription(`First one to type \`\`${key}\`\` wins \`\`${number}\`\` coins!`)
let channel = message.mentions.channels.first() || message.channel;
channel.send(event)
let filter = m => !m.author.bot;
channel.awaitMessages(filter)
.then(collected => {
if(collected.first().content === key) {
let winnerembed = new MessageEmbed()
.setColor('GREEN')
.setTitle('Someone claimed it!')
.setDescription(`${collected.first().author} was the first to type \`\`${key}\`\`!`);
channel.send(winnerembed)
if(!coins[collected.first().author.id]) coins[collected.first().author.id] = {
coins: number
}
if(coins[collected.first().author.id].coins > 0 || coins[collected.first().author.id].coins == 0) coins[collected.first().author.id] = {
coins: coins[collected.first().author.id].coins + '' + number
}
fs.writeFile("./coins.json", JSON.stringify(coins), (err) => {
if (err) console.log(err)
})
console.log('refresh')
} else return;
})
}
}``