简体   繁体   English

数据未保存到 json?

[英]Data not saving to json?

My code is something like this:我的代码是这样的:

if (y[1] == "suggestion_channel") {
    saveJson.servers[guild.id].suggestChannel = message.mentions.channels.first().id;
    message.channel.send("Set suggest channel to: <#" + saveJson.servers[guild.id].suggestChannel + ">");
}

var save = JSON.stringify(saveJson);
fs.writeFileSync('./data.json', save);

Now it all works BUT the only part that doesnt work is the saving part.... The FULL code can be found Here Please be nice as I have been trying to fix this for HOURS thanks: :D现在一切正常,但唯一不起作用的部分是保存部分.... 完整的代码可以在这里找到 请很好,因为我一直在努力解决这个问题,谢谢::D

UPDATE: Just use fs.writeFile not sync!更新:只使用 fs.writeFile 不同步!

The fs.writeFileSync() accepts a callback function, maybe use that and see if there is any error. fs.writeFileSync()接受一个回调 function,也许使用它并查看是否有任何错误。

Try something like this尝试这样的事情

 fs.writeFileSync('./data.json', save,function(err) { if (err) { console.log(err); } });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM