Discord.js-Bot-Development icon indicating copy to clipboard operation
Discord.js-Bot-Development copied to clipboard

My bot can't find the .env file and stops running. Help!

Open Spicyraz opened this issue 5 years ago • 1 comments

When I click run my bot runs for 1 second then just stops running I've read some of the error code (don't really understand it) but I found can't find .env.

Spicyraz avatar Apr 06 '20 20:04 Spicyraz

So basically, when you host on Glitch, you must have a file called .env (this file is created by Glitch on the creation of a new express app by default). This file is used to keep certain variables secret. These variables are stored inside an object called env which is stored inside another object called process. You can access your secret variables via process.env.

Here's a reference: image

Here's how to access your variable:

client.login(process.env.TOKEN);

This means your index.js file doesn't need to look after .env file. If this wasn't the right solution to your question please comment with the error message you're getting (possibly with some references too). :+1:

PantheraRed avatar Jun 05 '20 07:06 PantheraRed