javascript - 新脚本的语法错误 (vm.js :51:7) whilst running code for a discord bot in javascript

标签 javascript node.js discord

我在运行 Node index.js 时遇到错误 这是我的代码

const botconfig = require("./botconfig.json");
const Discord = require("discord.js");

const bot = new Discord.Client({disableEveryone: true});


bot.on("ready", async () => {
console.log(`${bot.user.username} is online!`);
}};

bot.login(botconfig.token);

这是我的错误信息

SyntaxError: missing ) after argument list
at new Script (vm.js:51:7)
at createScript (vm.js:138:10)
at Object.runInThisContext (vm.js:199:10)
at Module._compile (module.js:624:28)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:190:16)

希望你能帮上忙!

最佳答案

如果您在 new Script (vm.js:51:7) 处看到错误,这意味着您传递给 vm.js 的自定义脚本中存在错误,Node module that communicates with the V8 Virtual Machine .

vm.js 中的

new Script 只是评估您的代码。

所以你需要弄清楚你传递给V8虚拟机的代码有什么问题。如果您直接运行该文件(例如 node some/path/some_file.js),您应该得到指向实际错误的指针,如下所示:

YourPC:your-directory you$ node some/path/some_file.js
/some/system/path/your-directory./some/path/some_file.js:123
}};
 ^

SyntaxError: missing ) after argument list
    at new Script (vm.js:51:7)
    at createScript (vm.js:138:10)
    at Object.runInThisContext (vm.js:199:10)

错误消息上方带有 ^ 插入符号的部分向您展示了您自己的代码中的错误点。

在您的情况下,很容易发现:您有一个 }}; 应该是一个 });

如果您的代码看起来 100% 没问题但遇到了这个错误,例如@maevanapcontact 的失败箭头函数,可能您使用的是旧版本的 Node 和不支持该 ECMAScript 功能的旧版本 V8。 Arrow functions didn't have complete support until Node version 6 .

关于javascript - 新脚本的语法错误 (vm.js :51:7) whilst running code for a discord bot in javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48875059/

相关文章:

JavaScript/Ajax -- 文档加载,某些控件未加载

javascript - AWS DynamoDB 未返回对 Lambda 函数的响应

node.js - Nginx letsencrypt 配置慢

node.js - 如何使用 zmq (zeromq) 在两个 NodeJS 服务器之间发送多个请求并路由异步响应?

c# - Discord.NET Guild.DefaultChannel 不起作用

python - 如何使用python让Discord bot每天在特定时间运行一个函数?

javascript - id 字段的 Mongoose 请求返回 id 和 _id

javascript - LiveCycle Javascript 函数引用错误

javascript - ctrl + 数字键在浏览器中使用 javascript 触发事件

c# - Discord Bot [C#] 不执行命令