Hiding your secret tokens with Replit Secrets
Ok, so for the last few days I've seen quite a lot of questions in the ask space about hiding Discord Bot Tokens or other secrets now that the replit env's are gone.
A lot of people are panicking because their bots aren't working and they are afraid that they aren't going to be able to keep their token secret, but replit has already given out the answer, with the new secrets system. It's simple, easy to use, and frankly more intuitive then the old .env
files, I think it's awesome.
Now, if you want you can read the docs for replit secrets, right here: https://docs.replit.com/repls/secrets-environment-variables
Or you can take look at this step be step guide to using secrets.
First things first you need to open up the Secret's Manager (Is that it's real name???)
Then you need to create a secret, giving it a name and a value.
Secret's are so easy that replit automatically generates you the code to get the value of your secret, just press insert and it will put it into your code.
Make sure to IMPORT OS
import os #don't forget to import me!
or else you won't be able to read environment variables.
And just like that, secrets is working, keeping your token or secret message visible only to you.
can't someone just do print(os.environ("BOT_TOKEN"))
If someone forks your code the environ is deleted.
@NoobNotFoundI did all of this and for some reason it still doesn't work
Edit: I'm using Python
Hmm, so you have a key
and value
for that key right?
And what about your code to get the value, it should be secret = os.environ['KEYNAME']
@SHAD0Wmag1cks
I'll check again rn just to make sure I got all that
Great!
@SHAD0Wmag1cks
In java it is
System.getenv("ENV_KEY");
In nodejs, it is
process.env["ENV_KEY"]
Yep
process.env.ENV_KEY
in node IMO.