Keep your token safe

Where to store the bot token, what to do if it leaks, and why invited users should not see your .env.

1 min readDiese Anleitung auf Deutsch lesen

On this page 3
  1. Store it in .env
  2. If it leaks
  3. Invited users

Your bot token is a password to your bot. Anyone who has it can run your bot anywhere, read what it reads and post as it.

Store it in .env

Create a file named .env in the server root:

Properties
DISCORD_TOKEN=MTIz...your token...

Read it in code. Node: require('dotenv').config(); const token = process.env.DISCORD_TOKEN; (add dotenv to package.json). Python: from dotenv import load_dotenv; load_dotenv(); token = os.getenv("DISCORD_TOKEN") with python-dotenv in requirements.

Never paste the token into index.js, into a GitHub repo or into a ticket. If you share code with us, remove the token first.

If it leaks

Go to the Discord Developer Portal → your application → Bot → Reset Token. The old token stops working instantly. Put the new one in .env, restart.

Invited users

Anyone who may open files on the server (or has SFTP access) can read .env. Only invite co-developers as users with file permissions if you trust them with the token, or give them console-only rights.

Still stuck?

Kowalski, the assistant in your dashboard, reads your server's log and fixes most things on request. For everything else there is the ticket system.