在JavaScript中为Discord bot运行代码时,新脚本(vm.js:51:7)出现语法错误 [英] Syntax error at new Script (vm.js:51:7) whilst running code for a discord bot in javascript

查看:158
本文介绍了在JavaScript中为Discord bot运行代码时,新脚本(vm.js:51:7)出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行节点index.js时出错,
这是我的代码

I get an error whilst running my node index.js here is my code

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)

希望您能提供帮助!

推荐答案

如果在新脚本(vm.js:51:7)上看到错误 ,则表示您传递给vm.js的自定义脚本中存在错误,与V8虚拟机通信的节点模块

If you see an error at new Script (vm.js:51:7), it means there's an error in a custom script that you passed to vm.js, the Node module that communicates with the V8 Virtual Machine.

新脚本只是在评估您的代码。

new Script in vm.js is simply evaluating your code.

因此,您需要确定传递给V8虚拟机的代码中的错误。如果直接运行文件(例如 node some / path / some_file.js ),您应该得到指向实际故障的指针,

So you need to work out what the fault is in the code you passed to the V8 virtual machine. If you run the file directly (e.g. node some/path/some_file.js) you should get a pointer to the actual fault that looks like this:

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)

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

The part above the error message with the ^ caret shows you the faulty point in your own code.

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

In your case, it's pretty easy to spot: you have a }}; that should be a });.

如果您的代码看似100%正确,但是遇到此错误,例如@maevanapcontact的箭头功能失败,则可能是您在使用旧版本的Node和旧版本不支持ECMAScript功能的V8版本。 箭头功能直到节点版本6才得到完全支持。

If you have code that seems 100% fine but encounters this error, like @maevanapcontact's failing arrow functions, maybe you're using an old version of Node with an old version of V8 that didn't support that ECMAScript feature. Arrow functions didn't have complete support until Node version 6.

这篇关于在JavaScript中为Discord bot运行代码时,新脚本(vm.js:51:7)出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆