Configure and Verify Environment Variables for a Discloud‑Hosted Discord Bot
Learn how to add, restart, and confirm environment variables for your Discord bot on Discloud. This guide covers the exact steps, checks, and recovery options to keep your bot running securely.
13 Jul 2026, 03:40 UTC

Desired Outcome
After following this guide you will have a Discloud‑hosted Discord bot that reads its configuration from environment variables, can be restarted cleanly, and has a verified log entry confirming the variable value was applied.
Prerequisites
- Access to the Discloud web console with the project selected.
- Bot source code that reads configuration via
process.env(Node.js example) oros.getenv(Python). - A valid Discord bot token or other secret that you intend to store as an env var.
- Knowledge that env var names must be alphanumeric or underscore; no spaces or special characters.
Procedure
- Navigate to the Environment Variables Tab
- In the Discloud console, click the project name, then select the Environment Variables tab.
- Here you will see a list of existing variables and their status.
- Add or Update a Variable
- Click Add Variable (or edit an existing row).
- Enter the variable name, e.g.
DISCORD_TOKEN.- Discloud accepts only letters, numbers, and underscores.
- Do not include spaces or hyphens.
- Paste the token or secret value. Discloud will mask the value in the UI.
- Click Save.
- Restart the Bot
- In the console’s top bar, click Restart. This triggers a clean redeploy and injects the updated env vars into the runtime.
- Wait until the status changes to Running.
- Verify the Variable is Applied
- Open the View Logs pane. Use the search box to filter by a keyword you know the bot will log at startup, e.g.
Bot started. - Look for a log line that includes the variable name. Discloud masks sensitive values, but you should see a placeholder like
[REDACTED]or a partial hash. - Alternatively, add a debug command in your bot code that prints the value to the console. Example for Node.js:
client.on('messageCreate', msg => { if (msg.content === '!env') { msg.channel.send(`DISCORD_TOKEN is ${process.env.DISCORD_TOKEN}`); } });Send
!envin Discord, then check the console. The output should match the value you set.
- Open the View Logs pane. Use the search box to filter by a keyword you know the bot will log at startup, e.g.
Expected Checks
- Logs contain a startup line referencing the env var name, confirming the bot read it.
- Debug command output matches the value entered in the console.
- Variable status in the Environment Variables tab is marked Set.
Recovery Options
- If the bot fails to start after a variable change, revert the variable to its previous value in the console and restart again.
- Use the View Logs pane to inspect error messages. Look for exceptions related to missing tokens or invalid formats.
- If you accidentally expose a secret, delete the variable and create a new one with a fresh value.
Limitations & Practical Checks
- Discloud does not display the raw value of secrets in logs for security; you will see masked placeholders.
- Variable names containing special characters or spaces are rejected by the console; always use
^[A-Z0-9_]+$. - Changes to env vars do not take effect until a restart; if you forget to restart, the bot will continue using the old value.
- Confirm the variable is set by inspecting the Environment Variables tab after saving; the status should read Set.
Concrete Example
Below is a minimal Node.js bot showing how to read DISCORD_TOKEN and expose it via a debug command.
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.once('ready', () => {
console.log('Bot started, reading DISCORD_TOKEN');
});
client.on('messageCreate', msg => {
if (msg.content === '!env') {
msg.channel.send(`DISCORD_TOKEN is ${process.env.DISCORD_TOKEN}`);
}
});
client.login(process.env.DISCORD_TOKEN);
Deploy this code to Discloud, set the DISCORD_TOKEN variable in the console, restart, and run !env to confirm the value is correctly injected.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.