So, after it breaks, the JSON file looks like this
{
"server": {
"bans": {},
"mutes": {},
"kicks": {},
"warns": {},
"configs": {
"punishLogs": "false",
"punishLogchannel": "",
"actionLogs": "false",
"actionsLogsChannel": "",
"appLogs": "false",
"appLogsChannel": "",
"xprate": "1",
"levelRewards": {},
"levelMsgs": "false",
"levelChannel": "",
"levelMsg": "Congrats {member}! You've just hit level {level}!",
"premium": "true"
},
"levels": {
"266162824529707008": {
"level": 1,
"xp": 52
}
}
}
}
}
}
}
}
The code I use to write is like this
const Discord = require('discord.js');
const fse = require('fs-extra');
module.exports = {
name: "config",
description: "Configure the bot for your server.",
alaises: ['configs', 'settings', 'guildsettings', 'dashboard'],
usage: '<setting> <arguments>',
category: 'manager',
guildOnly: true,
example: 'No example.',
code(client, message, args) {
if (!message.member.hasPermission('ADMINISTRATOR')) return message.reply(`You are not permitted to configurate the bot for this server as you are not an administrator.`);
fse.readJson(`./databases/${message.guild.id}.json`, (err, db) => {
if (err) return message.reply(`Error, ${err}`).then(console.error(err));
//A lot of code.
db.server.configs.punishLogs = 'true';
return fse.writeFile(`./databases/${message.guild.id}.json`, JSON.stringify(db, null, 2))
Any way to make it not break my JSON files?