当我尝试在我的 VPS 上运行不和谐机器人时,我不断收到语法错误。我已经在 VPS 上安装了所有必需的东西...
/root/node_modules/random.js:12 client.on('ready', () => {
^ SyntaxError: Unexpected token )
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:945:3
const Discord = require('discord.js');
const request = require('superagent');
const fs = require('fs');
const client = new Discord.Client({ fetch_all_members: false,
api_request_method: 'sequential' });
client.login(***);
client.on('ready', () => {
console.log('ready!');
});
client.on('channelCreate', channel => {
console.log('made ${channel.name}');
});
client.on('guildMemberAdd', (g, m) => {
console.log('${m.user.username} joined ${g.name}');
})
client.on('guildMemberUpdate', (g, o, n) => {
console.log(o.nickname, n.nickname);
});
client.on('debug', console.log);
我使用的是 Node 版本 v0.10.46。
最佳答案
您正在使用 Node 的旧分支,该分支使用更旧版本的 V8,因此对新 ES6 语法的支持受到限制。
来自release versions页面:
- Version: Node.js v0.10.46
- Date: 2016-06-23
- V8: 3.14.5.9
- npm: 2.15.1
- NODE_MODULE_VERSION: 11
我们可以看到这个版本的Node使用V8版本3.14.5.9
。将此与使用 V8 5.1.281.83
的 v6.7.0 进行对比:
- Version: Node.js v6.7.0
- Date: 2016-09-27
- V8: 5.1.281.83
- npm: 3.10.3
- NODE_MODULE_VERSION: 48
可能的解决方案包括使用较新的 Node 分支,或者首先通过转译器运行代码。
关于javascript - Node.JS 不间断的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39929149/