一直显示“ throw err”错误消息

时间:2019-09-03 23:29:00

标签: node.js syntax-error discord.js

每次我让不和谐的bot联机时,自从我添加了一个小的json数据库以来,它就脱机并在控制台中显示此错误,而不会被命令触发。

export const createSession = (Session) => {
  return {
    type: 'setSession',
    Session: Session
  }
}

您知道,我对此很陌生,所以我不完全了解这里发生了什么错误。我试图浏览文件以了解代码中的错误,但我无法确切地说出问题所在。

这是我的indexDATA.js文件代码:

internal/modules/cjs/loader.js:800
    throw err;
    ^

SyntaxError: C:\Users\User\Desktop\Prince-Yami\entrydata.json: Unexpected token } in JSON at position 833
    at JSON.parse (<anonymous>)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:797:27)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.checkInData (C:\Users\User\Desktop\Prince-Yami\indexDATA.js:8:23)
    at Client.bot.on.msg (C:\Users\User\Desktop\Prince-Yami\index.js:47:17)
    at Client.emit (events.js:198:13)

这是我的entrydata.json文件:


module.exports = {
    checkInData: function(msg) {
        const Discord = require('discord.js');
        const bot = new Discord.Client();
        const PREFIX = 'sick.';
        const fs = require("fs")
        bot.entries = require('./entrydata.json')
        let args = msg.content.substring(PREFIX.length).split(" ");

        switch(args[0]){
            case 'entry':
              editedmsg = msg.content.slice(17);

              bot.entries [args[1]] = {
                message: editedmsg
              }
              const configD = JSON.stringify (bot.entries, null, 4)
              fs.writeFile ("./entrydata.json", configD, err => {
                if (err) throw err;
                msg.channel.send('Entry noted');
              });
            break;
            case 'entryget':
              let _message = bot.entries[args[1]].message;
              msg.channel.send(_message);
            break;
        }
    }
};

1 个答案:

答案 0 :(得分:0)

只需删除entrydata.json中的逗号:

{
    "00000": {
        "message": "**Scene 1**"
    }
}