0

I keep getting syntax errors when I attempt to run a discord bot on my VPS. I have all the required things installed on the 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);

I'm using Node version v0.10.46.

3
  • 2
    I'm guessing you have an old version of Node that does not support some of your ES6 syntax. Commented Oct 8, 2016 at 5:54
  • Information on which Node versions support arrow functions can be found here: node.green/#arrow-functions Commented Oct 8, 2016 at 5:57
  • @AlexanderO'Mara I have v0.10.46..... Commented Oct 8, 2016 at 5:57

1 Answer 1

1

You are using a legacy branch of Node which uses a much older version of V8, so support for new ES6 syntax is limited.

From the release versions page:

  • Version: Node.js v0.10.46
  • Date: 2016-06-23
  • V8: 3.14.5.9
  • npm: 2.15.1
  • NODE_MODULE_VERSION: 11

We can see this version of Node uses V8 version 3.14.5.9. Contrast this with v6.7.0 which uses V8 5.1.281.83:

  • Version: Node.js v6.7.0
  • Date: 2016-09-27
  • V8: 5.1.281.83
  • npm: 3.10.3
  • NODE_MODULE_VERSION: 48

Possible solutions include using a newer branch of Node, or running you code through a transpiler first.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.