I use dotenv to separate my bot tokens from the app itself. However, when I run the code it shows the env variables as undefined and as a result throws an error: Error: An invalid token was provided.
Here is the code requiring dotenv
require('dotenv').config()
const Discord = require("discord.js");
const client = new Discord.Client();
const {Client, Attachment, RichEmbed} = require("discord.js");
Here's the code calling the variable and the console.log where I attempted debug
console.log(process.env.BOT_TOKEN); // Display token test
client.login(process.env.BOT_TOKEN); // Login Token
Finally here is the config.env file itself
DEV_TOKEN="Not trying to leak the token"
BOT_TOKEN="Not trying to leak the token"
I'm not sure why it doesn't work.
You should create .env
file, not config.env