Anyone know how to use .env?(discord.py)
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.
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.
.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
os.environ.get, it'll look file a file called
.env. So make sure the file is called that. Repl.it will automatically hide that file if it has the correct name.