I made a dailycoins system for my discord bot, everything was ok, but now when I went to make another command, out of nowhere the bot gave an error.
Here's my code:
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
let coins = require('./coins.json');
const moment = require("moment");
const userData = JSON.parse(fs.readFileSync('./userData.json', 'utf8'));
client.on("ready", () => {
console.log("I am ready!"),
client.user.setActivity('-help | NOXUS')
});
client.login("TokenSecretoDaMorte");
///coins\\
client.on("message", async message => {
if (!userData[message.author.id + message.guild.id]) userData[message.author.id + message.guild.id] = {}
if (!userData[message.author.id + message.guild.id].lastDaily) userData[message.author.id + message.guild.id].lastDaily = "Ainda não coletado";
fs.writeFile('./userData.json', JSON.stringify(userData), (err) => {
if (err) console.log(err);
})
if (message.content === "-daily") {
if (userData[message.author.id + message.guild.id].lastDaily != moment().format('l')) {
userData[message.author.id + message.guild.id].lastDaily = moment().format('l')
coins[message.author.id] = {
coins: coins[message.author.id].coins += 15
};
fs.writeFile('./coins.json', JSON.stringify(coins), (err) => {
if (err) console.log(err)
});
message.reply('** acabaste de receber as tuas 15 DailyCoins.**');
} else {
message.reply('** já recebeste as tuas DailyCoins hoje, tenta novamente a ' + moment().endOf('day').fromNow() + '**');
}
}
});
This is the error:
undefined: 1
SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at Object. (/app/bot.js:6:23)
at Module._compile (module.js: 612: 30)
at Object.Module._extensions..js (module.js: 623: 10)
at Module.load (module.js: 531: 32)
at tryModuleLoad (module.js: 494: 12)
at Function.Module._load (module.js: 486: 3)
at Function.Module.runMain (module.js: 653: 10)
at startup (bootstrap_node.js: 187: 16)
at bootstrap_node.js: 608: 3
I hope you can understand, this is the first time I use this platform. I tried to adapt not to get a giant code.