Anyone know how to use .env?(

I'm trying to hide my token in a .env file so people can't get my bot's token, and I don't know how to get my token variable from the file.
TOKEN=da token(not telling u lol)
token = os.getenv("TOKEN")

I have a feeling that my code is wrong, but I don't know what the right code is.

You are viewing a single comment. View All
Answered by AloegelhiPlaysR [earned 5 cycles]
View Answer

Yes, I know that this question has already been answered, but no one has explicitly explained why your file didn't work, so I'm gonna answer that.

So .env files, of course, can only be seen by the repl owner. When making a .env file, only name it .env. It's not supposed to be an extension name.

When you call for a variable from .env with os.getenv or os.environ.get, it'll look file a file called .env. So make sure the file is called that. will automatically hide that file if it has the correct name.


@EpicRaisin idk if you are still getting replies, but when i try and create a file thats only called this, it does not let me.


@luigirandoli changed the system so now you don't need to make a file. Instead, you just go to the Secrets tab (the one with the lock) to make secrets, and it'll still work with the same code.