存储文件格式不正确(JSON意外结束)discord.js

存储文件格式不正确(JSON意外结束)discord.js,discord,bots,discord.js,Discord,Bots,Discord.js,我在做一个赠品机器人,结果出错了。这是全部错误 (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)

我在做一个赠品机器人,结果出错了。这是全部错误

(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)
这是我的密码:

const { GiveawaysManager } = require("discord-giveaways");
const manager = new GiveawaysManager(bot, {
    storage: "./giveaways.json",
    updateCountdownEvery: 10000,
    default: {
        botsCanWin: false,
        embedColor: "#FF0000",
        reaction: "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:

{}
const{giveawaymanager}=require(“不和谐的赠品”);
const manager=新的赠品管理器(bot{
存储:“./givaways.json”,
更新计数每小时:10000,
默认值:{
博茨坎温:错,
嵌入颜色:“FF0000”,

反应:"存储文件是您的
/giveaways.json
。如中所示,它以极有可能出错的json格式保存文件,请确保您没有接触
giveaways.json
文件,更不用说对其进行更改了。在
giveaways.json
文件中添加一行可能会导致
giveawaymanager
错误地追加而不能阅读

我的建议基本上是删除
/giveaways.json
文件。这将刷新文件并消除所有语法错误,除非它来自npm模块本身。请注意,删除它将删除并因此停止所有正在进行的赠品,因此请确保您没有正在进行的赠品

如果这不能解决问题,则再次删除
/giveaways.json
文件,并创建一个新的
/giveaways.json
文件,其中包含以下内容:


我也有同样的问题,结果是giveaways.json文件中只有一个
[]

最好不要添加文件,因为模块应该为您添加一个文件!

您没有提供足够的代码,没有人知道GivawayManager的构造函数是什么样子以及它是做什么的。从错误消息判断,您假设从服务器端返回的任何内容都是json数据,而这不是必需的如果是这样的话,要么服务器用格式错误的json进行回复。