discordjs / guide

The official guide for discord.js, created and maintained by core members of its community.
https://discordjs.guide
MIT License
1.57k stars 2.31k forks source link

SyntaxError: Unexpected token `(` #424

Closed InvertedStone closed 4 years ago

InvertedStone commented 4 years ago

I have followed every step, but fore some reason it gives me an error message which is the following: SyntaxError: Unexpected token ) at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (C:\Users\Home\Desktop\hexbot\node_modules\discord.js\src\index.js:3:14) at Module._compile (module.js:570:32)

My code is the same thing as the list. I use the recommended node.js and Visual Studio Code. Any help is appreciated :D

0x57e11a commented 4 years ago

Can you post your code in a code block? Use: ``` code here ```

InvertedStone commented 4 years ago

@Consoli0 Here is my code

const Discord = require('discord.js');
const client = new Discord.Client();

client.once('ready', () => {
    console.log('Ready!');
});

client.on('message', message => {
    if (message.content === '!ping') {
        message.channel.send('Pong.');
    }
});

client.login('NzMwNTIzMjA3ODYxNDAzNzU5.Xwc1Cw.hdU76z49PmqksorH8zAoFY7O7JI');
anandre commented 4 years ago

Please do not ignore the issue template. If you have any questions about the discord.js library usage, please ask them in the Discord Server instead. https://discord.gg/bRCvFy9 **

Your syntax errors are not issues with the library and don't belong here. We suggest you install a linter. Additionally, you'll want to regenerate your token immediately.

Smarter people than me also suggested it could be out-of-date Node. The library requires node v12.0.0 or higher.

almostSouji commented 4 years ago

Firstly: Please re-read our section about tokens and why you should never give them to anyone (including a github thread). Luckily Discord token invalidation is integrated into GitHub and you will need to get a new one regardless.

Secondly: Your heading and error paste show different issues, quite odd.

I can not reproduce this behavior and can run the linked code (and "resulting code sample" listing) without any issues. Please provide the actual versions of both discord.js and node and make sure you run both commands in your bots project folder.

npm list discord.js
node --version

I am running on node.js v13.6.0 and discord.js 12.2.0 and 11.6.4 respectively.

0x57e11a commented 4 years ago

How are you running your code? That error does not appear to coincide with the code you provided, and the stack trace isn't helpful either

InvertedStone commented 4 years ago

Firstly: Please re-read our section about tokens and why you should never give them to anyone (including a github thread). Luckily Discord token invalidation is integrated into GitHub and you will need to get a new one regardless.

Secondly: Your heading and error paste show different issues, quite odd.

I can not reproduce this behavior and can run the linked code (and "resulting code sample" listing) without any issues. Please provide the actual versions of both discord.js and node and make sure you run both commands in your bots project folder.

npm list discord.js
node --version

I am running on node.js v13.6.0 and discord.js 12.2.0 and 11.6.4 respectively.

I have regenerated the token :D so no need I use the recommended node and latest discord.js.

InvertedStone commented 4 years ago

Please do not ignore the issue template. If you have any questions about the discord.js library usage, please ask them in the Discord Server instead. https://discord.gg/bRCvFy9 **

Your syntax errors are not issues with the library and don't belong here. We suggest you install a linter. Additionally, you'll want to regenerate your token immediately.

Smarter people than me also suggested it could be out-of-date Node. The library requires node v12.0.0 or higher.

As i said i have regenerated the token, my node is the one recommended in the website

InvertedStone commented 4 years ago

How are you running your code? That error does not appear to coincide with the code you provided, and the stack trace isn't helpful either

I followed this toturial.

almostSouji commented 4 years ago

Please understand that "recommended" is not a version and actually execute the provided commands and show the output:

npm list discord.js
node --version

Without further information there is nothing anyone can do. The tutorial you keep linking is completely valid and runs on node.js v13.6.0 (anything newer than 12.0.0) and discord.js 12.2.0 and 11.6.4 without any issues.

InvertedStone commented 4 years ago

Thanks, the problem was i was using an older version of node thx :D