Reputation: 339
I'm working on a giveaway bot and got that error. This is the full error
(node:4) UnhandledPromiseRejectionWarning: SyntaxError: The storage file is not properly formatted (Unexpected end of JSON input).
at GiveawaysManager.getAllGiveaways (/app/node_modules/discord-giveaways/src/Manager.js:308:27)
at async GiveawaysManager._init (/app/node_modules/discord-giveaways/src/Manager.js:391:30)
Here is my code:
const { GiveawaysManager } = require("discord-giveaways");
const manager = new GiveawaysManager(bot, {
storage: "./giveaways.json",
updateCountdownEvery: 10000,
default: {
botsCanWin: false,
embedColor: "#FF0000",
reaction: "🎉"
}
})
bot.giveawaysManager = manager;
}
})
I'm new to coding so it wil be great if you explain in baby steps
Upvotes: 0
Views: 691
Reputation: 373
I had this same issue, and it turns out that the giveaways.json file only had a []
in it.
It is best if you just don't add a file because the module should add one for you!
Upvotes: 2
Reputation: 761
The storage file is your ./giveaways.json
. As seen in the npm documentation, it saves the file in JSON format which is highly likely to go wrong, make sure that you haven't touched the giveaways.json
file, much less change it. Adding even a single line in the giveaways.json
file may cause the GiveawaysManager
to append wrongly and not be able to read it.
My suggestion is basically delete the ./giveaways.json
file. This should refresh the file and be rid of all syntax errors unless it was from the npm module itself. Note that deleting it, will delete and therefore, stop all the giveaways in process, so make sure you have no giveaways in progress.
If this doesn't fix the issue, then delete the ./giveaways.json
file again, and create a new ./giveaways.json
file with this as it's contents:
{}
Upvotes: 0