【发布时间】:2021-12-19 17:50:25
【问题描述】:
我在为我的 discord 机器人创建主文件时遇到问题。目前,我在尝试让我的机器人工作时遇到问题,但遗憾的是,此错误消息已从控制台输出。
PS C:\Users\Kelvin Wang\Documents\Projects\DiscordBot> node index.js
node:internal/modules/cjs/loader:1170
throw err;
^
SyntaxError: C:\Users\Kelvin Wang\Documents\Projects\DiscordBot\config.json: Unexpected end of JSON input
at parse (<anonymous>)
at Object.Module._extensions..json (node:internal/modules/cjs/loader:1167:22)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\Kelvin Wang\Documents\Projects\DiscordBot\index.js:4:19)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
我在 index.js 中的代码是这样的:
//initial discord initialization of client and library
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
const dotenv = require('dotenv');
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ferraribot is online!');
});
// Login to Discord with your client's token
client.login(token);
虽然我的 config.json 看起来像这样:
{
"token": "token"
}
任何帮助将不胜感激!这是我第一次使用堆栈溢出,所以对于我所做的任何错误格式,我深表歉意。提前致谢!
【问题讨论】:
-
请编辑您的问题并删除您的机器人令牌以防止其他用户访问您的机器人,然后重新生成一个新令牌以确保安全:)
-
哦,是的,我忘了隐藏我的机器人令牌,谢谢提醒 :)
-
@KelW 重新生成您的令牌,因为如果有人试图查看人们编辑的内容,它在历史记录中可用,例如您的令牌看起来像这样 -
OTA2MTQxNDM0MjMzNjQzMDE5.YYUT-Q.rdlx5P4CxPH5ShKINNBrp3*****
标签: javascript node.js json discord discord.js