ACLClouds
ACLClouds

Where to store tokens and environment variables?

Separate configuration and code, limit access and regenerate an exposed secret. A token in Git or in a screenshot should be considered compromised.

A token in Git or in a screenshot should be considered compromised. The panel allows you to pass variables to the process without writing them in the code.

Step-by-step procedure

  1. Naming variables

    Use meaningful names like DISCORD_TOKEN, DATABASE_URL or API_KEY.

  2. Enter in Startup

    Paste the token into the “Discord token” field, or add the variable with “Name”, “Value” and then “Add”. Hide secrets in screenshots.

  3. Read from code

    Use process.env in Node.js or os.environ in Python.

  4. Don't commit .env

    Add .env to the .gitignore and only provide a valueless .env.example.

  5. Respond to a leak

    Revoke the token on the original service, generate a new one and update the panel.

.gitignore

.env
.env.*
!.env.example

Reading the token in Node.js

const token = process.env.DISCORD_TOKEN;
if (!token) {
  console.error('DISCORD_TOKEN is missing: add it in the Startup tab.');
  process.exit(1);
}
client.login(token);

Reading the token in Python

import os
import sys

token = os.getenv("DISCORD_TOKEN")
if not token:
    sys.exit("DISCORD_TOKEN is missing: add it in the Startup tab.")
client.run(token)

Where to set the variables

A bot’s variables are set in the “Startup” tab, “Environment variables” section. The “Discord token” field is DISCORD_TOKEN. For any other variable, fill in “Name” and “Value” below the list, then click “Add”.

A variable that is already listed is saved as you type. The bot receives it at the next start: restart it from the console. Values are stored encrypted. The bot owner sees them in plain text in Startup, so keep that in mind before sharing your screen; an invited user only sees the names.

  • Name: uppercase letters, digits and _, 64 characters at most.
  • Refused because reserved for the system: PATH, HOME, USER, PORT, HOSTNAME, NODE_OPTIONS and names starting with LD_.

Reading the variables in your code

If you use dotenv or python-dotenv locally, keep them: by default they do not replace a variable that is already defined. The Startup values therefore take priority over a .env file left in the bot’s files.

Never print process.env or os.environ in full: those lines stay in the console and go out with “Copy all logs”.

No secrets in a ticket

Support does not need the full token to diagnose a startup.

Frequently asked questions

The console says a variable is not defined: what should I do?

When the bot stops right after launching, the platform looks in its output for variables read by the code but missing or empty, and adds a line such as “Variable DISCORD_TOKEN is not defined in Startup variables”. Add it in Startup with exactly that name, including case, then restart the bot.

Why does a Python bot fail with KeyError: 'DISCORD_TOKEN' at startup?

os.environ["DISCORD_TOKEN"] raises this error when the variable does not exist in the bot’s environment. Compare the name with the one in your code, including uppercase and _. If the name is right, restart: a variable added while the bot is running is only passed on at the next launch.

My token was published on GitHub: what should I do?

Treat it as compromised, even after deleting the file: the Git history keeps it. In the Discord Developer Portal, “Bot” tab, click “Reset Token”; the old token stops working at once. Paste the new one into “Discord token”, restart the bot, then add .env to .gitignore. Discord may also reset a token found in a public repository on its own.