Bot hosting
Token and variables
Your Discord token, and anything else your bot reads from its environment, goes in the Variables tab. Nothing secret needs to be in your code.
Add your token #
- Open the Variables tab and press Add a variable.
- Name it what your code expects, for example
DISCORD_TOKEN. - Paste the token as the value and save.
Your bot is given every variable when it starts. A change takes effect at the next start or restart.
In code, read it the way you would anywhere else:
// Node.js
const token = process.env.DISCORD_TOKEN;
# Python
import os
token = os.environ["DISCORD_TOKEN"]
Where variables are kept #
They are stored in a file called .env in your bot's top folder, which is where most bots already look for them. So:
- You can also write
.envby hand in the Files tab. The Variables tab shows what is in it. - If you already have a
.envon your computer, Upload a .env file on the Variables tab reads it in. Its variables are added to the bot's; a name the bot already has takes the file's value; nothing else is removed. - A backup of the bot includes the file, so a restored bot has its token.
Values are hidden on the page until you press Show. Anyone you give the file or a backup to can read them.
Rules #
| Name | Letters, numbers and underscores |
| Value | One line |
| How many | Up to 50 |
Warning
If a token ever leaks, reset it in the Discord Developer Portal first, then change it here. A leaked token lets anyone run your bot as you.