Reputation: 105
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.
Upvotes: 2
Views: 2391
Reputation: 888
Quote marks aren't required in the .env
file. Could you try removing them and seeing if it works (with no space after the equals sign)?
Upvotes: 1