javascript - 尝试运行 "node ."时出现语法错误如何修复?

标签 javascript node.js discord discord.js

我刚刚开始学习,这是我在尝试启动机器人时遇到的错误。 关于如何解决这个问题有什么想法吗?

语法错误是:

    SyntaxError: C:\Users\Thela\code\config.json: Unexpected end of JSON input
        at JSON.parse (<anonymous>)
        at Object.Module._extensions..json (internal/modules/cjs/loader.js:987:27)
        at Module.load (internal/modules/cjs/loader.js:812:32)
        at Function.Module._load (internal/modules/cjs/loader.js:724:14)
        at Module.require (internal/modules/cjs/loader.js:849:19)
        at require (internal/modules/cjs/helpers.js:74:18)
        at Object.<anonymous> (C:\Users\Thela\code\index.js:2:16)
        at Module._compile (internal/modules/cjs/loader.js:956:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
        at Module.load (internal/modules/cjs/loader.js:812:32)

index.js

    const Discord = require('discord.js');
    const config = require('./config.json');
    const client = new Discord.Client();

    client.once('ready', () => {
        console.log('Ready!');
    });

    client.on('message', message => {
        if (message.content === '!ping') {
            message.channel.send('Pong.');
        }
    });

    client.login(config.token);
    enter code here

config.json 是

    {
        "prefix": "!",
        "token": "<my-token>",
    }

最佳答案

config.json 应该是这样的:

{
    "prefix": "!",
    "token": "<my-token>"
}

第 3 行的“,”不应该出现在这里。

关于javascript - 尝试运行 "node ."时出现语法错误如何修复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58711544/

相关文章:

python - 如何让 Discord 机器人在添加时需要 x 权限?使用Python

javascript - JQuery/Javascript 冲突? - 根据选择选项显示/隐藏 div 不起作用

javascript - 事件处理程序之间的一个 $this 分配

JavaScript : can't initialize an object property with an array of function

angularjs - 从 80 端口到另一个端口的 Angular $http 请求

python - 如何在我的 Discord 机器人中正确解析标记用户?

javascript - Discord Bot Node JS 简单错误.send

javascript - 为什么 key 是 for ... in 中的字符串

javascript - 基于 JavaScript 的倒计时时钟问题

node.js - app.use ('*' ) 和 app.all ('*' ) 在 Express 中的区别