Learn to Code via Tutorials on Repl.it!

← Back to all posts
Hiding your secret tokens with Replit Secrets
h
InvisibleOne

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

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.

Voters
InvisibleOne
Comments
hotnewtop
EpicGamer007

In java it is
System.getenv("ENV_KEY");

In nodejs, it is
process.env["ENV_KEY"]

InvisibleOne

Yep

codingjlu

@EpicGamer007 it's easier to just use process.env.ENV_KEY in node IMO.

EpicGamer007

@codingjlu yes that works too.its a javascript object so either way works

SHAD0Wmag1cks

I did all of this and for some reason it still doesn't work

Edit: I'm using Python

InvisibleOne

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

SHAD0Wmag1cks

I'll check again rn just to make sure I got all that

SHAD0Wmag1cks

@InvisibleOne Aight, I had to make an adjustment, but I got it now

InvisibleOne
SHAD0Wmag1cks

@InvisibleOne But how would I know for sure if it's working?