I'm doing the discord.js getting started bot but I always get this error: SyntaxError: Unexpected token?
This is the code I used, actually just copy and paste from their tutorial just switched to dotenv for the token...
// Require the necessary discord.js classes
require("dotenv").config();
const { Client, Intents } = require('discord.js');
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready!');
});
// Login to Discord with your client's token
client.login(process.env.TOKEN);
These are the versions of discord.js and dotenv I'm using. Node version is 12.8.0
"dependencies": {
"discord.js": "^13.1.0",
"dotenv": "^10.0.0"
}
Already thanks for your help guys!
CodePudding user response:
So the first thing to note is that your error is coming from node_modules
. That means that the code that is erroring is code that you've imported from npm
to do something. Because it's not your code and rather third party code that probably works, that means that the error most likely has to do with either your version of that code or the way you're using that package is incorrect.
My best guess would be that it has to do with some advanced syntax that the package is using, but that errors on your machine because you have version incompatibility. I'd recommend updating your node version and trying again. Let us know if that fixes the problem!
Download latest node version: https://nodejs.org/en/download/