Environment variables (.env): Discord bots and apps

Step-by-step guide

you understand what the “Variables” screen is for and how to store a secret (bot token, API key) without writing it in your code.

Time : 5 minutesLevel : intermediateChecked : 17 Nov 2026

Before you start

  • An environment variable is a setting or a secret your program reads at startup, for example DISCORD_TOKEN. It lives in a .env file rather than in the code, so you do not publish it by mistake.
  • This screen mostly matters for Discord bots and apps (Node.js, Python). For a game server, settings live in “Démarrage” (Startup) or “Propriétés” (Properties).
1

Open the screen

Variables menu (Manage section). The list shows one key and one value per row; it says “No variables found” until you create one. Two buttons: Add Variable and Create Backup.

Environment variables (.env): Discord bots and apps : Variables screen
Variables screen
2

Add a variable

Click Add Variable. The “Add/Edit Variable” window asks for:

  1. Environment: the file concerned, among .env, .env.development, .env.production and .env.local. For a live bot, use .env.
  2. Key: the variable’s name, in capitals (DISCORD_TOKEN).
  3. Value: its value.

Then Add Variable.

Add variable window
Add variable window
3

Use the variable in your program

In your code, read the variable instead of hard-coding it: in Node.js process.env.DISCORD_TOKEN, in Python os.environ["DISCORD_TOKEN"]. Then restart the server so it takes effect.

4

Protect your secrets

  • Never put a token or password in a public repository, a screenshot or a Discord message.
  • The account’s Privacy mode hides sensitive information in the panel before a screenshot or a stream.
  • If a token leaked, regenerate it with its issuer (for example in Discord’s developer portal), then replace the value here.

If it does not work

My variable is ignored

check the exact name (capitals included), the file chosen in Environment, and restart the server.

My bot says “invalid token”

the value is incomplete or expired; copy the whole token again.

I cannot find the screen on my game server

it appears in every server’s menu, but only matters for apps that read a .env.

Questions? Get in touch

Our team will answer by message or on Discord.

No game server yet?

Launch yours in minutes. €1 = 1 GB.

Browse our games