Skip to content
Sign upLog in
← Back to Community
Hide Discord Bot Token in Python
Profile icon
cL3v3r47

I've been searching everywhere and everyone is talking about github or .js files.. I want to hide my bot token in Python, but my main.py says

import discord
from discord.ext import commands
import random
from discord import Permissions
from colorama import Fore, Style
import asyncio

token = ""

I can't hide my token, can anyone help me? cuz im new in coding and these stuff.

Voters
Profile icon
Phi-LongLong2
Profile icon
cL3v3r47
Comments
hotnewtop
Profile icon
Coder100

try using secrets: https://docs.replit.com/programming-ide/storing-sensitive-information-environment-variables

replit is different from other ones, not sure what they mean by .js files, but certainly .gitignore files don't work on repl.

Profile icon
ch1ck3n

go to the sidebar and click on the lock

add a new key called EPIC_BOT_TOKEN and then for the value add your token

now go to your code, and import os like import os

then do this:

token = os.getenv['EPIC_BOT_TOKEN']

it will not be accessible by anyone so no worries

Profile icon
cL3v3r47

@ch1ck3n

import discord
from discord.ext import commands
import random
from discord import Permissions
from colorama import Fore, Style
import asyncio
import os

token = os.getenv['EPIC_BOT_TOKEN']

It says:
Traceback (most recent call last):
File "main.py", line 9, in
token = os.getenv['EPIC_BOT_TOKEN']
TypeError: 'function' object is not subscriptable

Profile icon
ch1ck3n

@cL3v3r47

oh i am sorry token = os.getenv('EPIC_BOT_TOKEN')

Profile icon
cL3v3r47

@ch1ck3n
Thx very much :)

Profile icon
ch1ck3n

@cL3v3r47
if you click on the checkmark next to my name you can pay respects

Profile icon
SixBeeps

@ch1ck3n
smh imagine asking for answered status

Profile icon
ch1ck3n

@SixBeeps
it is buisness