Skip to content
Sign upLog in
← Back to Community
Hiding your secret tokens with Replit Secrets
Profile icon
hacker
has Hacker Plan
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???)

Screen Shot 2021-05-13 at 8.29.24 AM

Then you need to create a secret, giving it a name and a value.

Screen Shot 2021-05-13 at 8.29.58 AM

Screen Shot 2021-05-13 at 8.30.32 AM

Screen Shot 2021-05-13 at 8.31.03 AM

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.

Screen Shot 2021-05-13 at 8.31.53 AM

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.

Screen Shot 2021-05-13 at 8.33.00 AM

Voters
Profile icon
InvisibleOne
Comments
hotnewtop
Profile icon
EpicGamer007

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

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

Profile icon
InvisibleOne

Yep

Profile icon
codingjlu

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

Profile icon
EpicGamer007

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

Profile icon
NoobNotFound

can't someone just do print(os.environ("BOT_TOKEN"))

Profile icon
InvisibleOne

If someone forks your code the environ is deleted.

@NoobNotFound

Profile icon
NoobNotFound

@InvisibleOne
no like not forking the project all they have to dod is go in the console on the right and do the code not like fork it then type the code

Profile icon
SHAD0Wmag1cks

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

Edit: I'm using Python

Profile icon
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

Profile icon
SHAD0Wmag1cks

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

Profile icon
SHAD0Wmag1cks

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

Profile icon
InvisibleOne
Profile icon
SHAD0Wmag1cks

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