I'm new to discord.js and I have no clue why I'm getting this error:
Uncaught Error [TOKEN_INVALID]: An invalid token was provided.
my bot.js file
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.on('ready', () => {
console.log(`Successfully Logged in as ${client.user.tag}!`);
});
client.login(process.env.TOKEN);
.env file
TOKEN='my Bot token here'
I'm 100% sure that my bot token is correct/valid, I have also tried revoking it and copy-pasting the new token several times, but I still get the same error... I have searched up nearly everywhere on the net and I still haven't found a solution to my problem.
package.json file
{
"dependencies": {
"discord.js": "^13.6.0",
"dotenv": "^16.0.0"
}
}
Did you initialize the env to be used in your file?
You will have to use dotenv package.
Put require('dotenv').config() at the top of your file and you would be good to go