Env Variable not Working

Hi there,

This is my first post, so I apologize if I’ve done something incorrectly.
I’m using Glitch to host a Discord bot and I’m trying to use the env file to hide my bot token. However, whenever I run my bot I get an error saying the variable is an invalid bot token. The bot I am running is Dragory Modmail. I am very inexperienced when it comes to this, so please be aware of that.
Thank you,
Red.

Firstly, just make sure that your scripts are actually able to retrieve the bot token by using console.log() to debug. Do you think you might be mistakened for using the ‘Client Secret’ of your Discord bot and not the ‘Token’ of the bot? I know that alot of people gets mixed up between these two very different things. If you are using the bot token, and the scripts are able to retrieve the token from your .env file, try regenerating your bot token and try again.

Bot token can be located at:
**

**

Can you be more specific on what you mean by using console.log() to debug?
Also, the token works if I input the token instead of use the variable, so it’s definitely the token.

I haven’t programmed a discord bot in a while but from what I can remember I had to regenerate my token whenever this happened.
I normally regenerated it 2-4 times and then used the new one.

1 Like

Pretty much just typing console.log(env.YOURTOKEN) in a js script to make sure that your token is actually retrievable.

.env values are retrieved using PROCESS.env.SECRET_NAME. So try logging PROCESS.env.YOURTOKEN.

1 Like

I’m not sure how to do that exactly. Do I input the token in a new project’s env file and try to console.log() it there?image

Make sure that you have your token in your .env file,

And then your java script file, type console.log(process.env.TOKEN), (please remember to not show this to anyone, as they may get hold of your bot).

If the token does match with what you have in your .env file, then maybe try regenerating your discord token again and check that your not using the client secret again.

1 Like

If I open my logs, then my token should pop up there automatically? That’s what happened with me when I opened a new project, coded console.log(process.env.SECRET), and had my token in the .env file.

However, in my bot project I always get errored.

If I open my logs, then my token should pop up there automatically?

No, console.log(process.env.SECRET) is supposed to tell you what the token is to the log. If you don’t have console.log(process.env.SECRET) in any of your js scripts, your token won’t show up in the logs.

Yes, I had console.log(process.env.SECRET) in my new project’s code, and my token appeared in my logs.

you can put the proyect in private

you put process.env.token in config.ini but process.env is for node.js so you need to configure the token in the js file. i’m inexperienced in node. i don’t know anything but i wanted to help