TABI CLOUD
Bots

Bot .env files and token safety: keep your secrets private

5 min read · Updated October 2026 · By Tabi Cloud

Your bot token is like a password. Anyone who has it can control your bot, so it should never be written directly into code you share.

What is a .env file?

A .env file is a plain text file that holds settings as simple NAME=value lines, for example a line that starts with TOKEN= followed by your token. Your code reads these values at startup instead of containing them.

Setting it up

  1. Create a file named exactly .env in your bot folder.
  2. Add one line per secret, with no spaces around the equals sign.
  3. Load it at the top of your code and read the value from the environment.
  4. Add .env to your .gitignore file so it is never committed.

On your hosting panel

Upload the .env file through the Files tab, next to your main bot file. Some panels also offer startup variables in a settings area, which is another option. Check what your panel provides, and keep one method so you do not get confused about which value is used.

Rules to follow

If your token leaks

  1. Reset it immediately in the Discord Developer Portal (or revoke it with BotFather for Telegram).
  2. Update your .env file with the new token.
  3. Restart the bot.
  4. Check your bot servers for strange activity.

Discord automatically scans some public places and may reset tokens it finds, but do not rely on that. Treat any exposed token as compromised.

Want your own server? Join our Discord and tell us the game. We set it up and send you the details. Need help with an error from this guide? Open a ticket there.

GET STARTED ON DISCORD

More guides

BotsHow to keep your Discord bot online 24/7BotsHow to host a Discord bot (discord.js and discord.py) and fix common errorsBotsHow to host a Telegram bot 24/7