I tried to look into other ideas of what might be the issue, but it usually comes down to not adding in the extension, or adding the extension when it isn't there, or mainly just spelling. I have double checked all of that and I'm still not sure why this error is popping up. I assume it has to do with the readFileSync but I'm not even sure what else I would put in place of that.
Basically what I'm trying to do is store the amount of candy users get in a json file. No I don't want to use a database as this is only a temporary thing for Halloween. The code I found to store the info was from a few years ago so I know the code is outdated, but I've looked and I'm still unsure on how it's supposed to be.
const fs = require('fs');
const candyAmount = JSON.parse(fs.readFileSync('DiscordBot/candyheld.json', 'utf8'));
module.exports = {
name: 'trickortreat',
description: 'Special Halloween command',
execute(message, args) {
if (!candyAmount[message.author.id]) {
candyAmount[message.author.id] = {
candyStored: 5
}
return message.channel.send('For starting this event, you have received 5 pieces of candy!')
}
// Stores a random number of candy from 1-3
let candy = Math.floor(Math.random() * 3);
// Sets the possible messages to be received
let trickortreatmessage = [
'The scarecrow standing behind you jumps out at you and makes you drop all your candy!',
`${guild.members.random()} was nice enough to give you Candy! You got ${candy} pieces of candy!`,
`Oh no you asked ${guild.members.random()} for Candy and they decided to egg you instead!`
]
// Store one of the random messages
const trickortreat = Math.floor(Math.random() * trickortreatmessage);
if (trickortreat == trickortreatmessage[0]) {
candyAmount[message.author.id].candyStored - candyStored;
} else if (trickortreat == trickortreatmessage[1]) {
candyAmount[message.author.id].candyStored + candy;
}
fs.writeFile('DiscordBot/candyheld.json', JSON.stringify(candyAmount), err => {
if (err) console.error(err);
});
message.channel.send(trickortreat);
},
};