使用常量的Discord命令提示符错误



何时进入

"节点索引.js";

进入命令提示符&包含所有Discord机器人信息的文件夹,它会给我这个错误:

const client = Discord.Client();
^^^^^
SyntaxError: Unexpected token const
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
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 Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

有什么需要修复的吗?

编辑:

config.json

{ 
"BOT_TOKEN": "bot's token"
}

index.js

const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.login('bot's token');

据我所见,您可能已经将其中一个放在代码中:(可能是意外地放在了另一个.js文件中?(

const client = Discord.client();

SyntaxError:意外的标记const,通常意味着应用程序等待某种const,但没有收到。另外,尝试移动index.js文件中的"Token"常量。

这表明您的代码中有const client = Discord.Client();。一旦发现,就把它移走。

建议

我建议你参考一下你的config.json

以下内容:

const settings = require('./config.json')

然后通过制作一个变量提取机器人令牌:

const token = settings.BOT_TOKEN;

结果:

client.login(token);

优化代码;(

最新更新