Why your bot shouldn't run on your own PC
As long as your bot runs on your own computer, it goes offline when your PC shuts down, goes to sleep or your internet drops for a moment. For a server with members that's annoying: commands stop working, moderation stops and welcome messages don't arrive. A host keeps your bot online 24/7 and restarts it if it crashes.
On the Pro plan of Zeno hosting (€10 a month) you run Node.js and Python bots with 1 GB of memory. The platform recognises a Discord bot by itself: a bot doesn't need a web page, so it's started as a background process and kept an eye on.
Step 1: take the token out of your code
Your bot token is your bot's password. Never put it in your code and never on GitHub: whoever has the token has your bot. Read it from an environment variable instead.
discord.js (JavaScript)
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once("ready", () => console.log(`Online as ${client.user.tag}`));
client.login(process.env.DISCORD_TOKEN);
discord.py (Python)
import os
import discord
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print(f"Online as {client.user}")
client.run(os.environ["DISCORD_TOKEN"])
Using a .env file locally is fine. The Zeno CLI never uploads .env.
Step 2: check your project files
The platform installs and starts your bot automatically if your project looks like this:
| discord.js | discord.py | |
|---|---|---|
| Dependencies | package.json with discord.js | requirements.txt with discord.py |
| Install | npm install (or pnpm/yarn, based on your lockfile) | pip install -r requirements.txt |
| Start | the start script, otherwise index.js, server.js, app.js or main.js | main.py, app.py, server.py or bot.py |
Is your project different? Then set your own Start command in your project's settings.
Step 3: create a server project
Log in to the dashboard, click New project and choose Server. Add your code by uploading it or connecting a GitHub repository. Prefer the terminal? Go to your bot's folder and type:
zeno login
zeno --prod
The CLI asks whether it's a website or a server. Choose server.
Step 4: set your token as an environment variable
Open your project's settings and under Environment variables add a variable named DISCORD_TOKEN with your token as its value. You'll find your token in the Discord Developer Portal, under your application at Bot. Got more secrets, like an API key for AI? Add them the same way.
Step 5: deploy
Click Deploy. You'll see live how the dependencies are installed and the bot is started. When Online as … appears in the logs, your bot is live. From now on it:
- runs 24/7, even when your computer is off;
- restarts by itself if it crashes;
- shows all logs and errors live in the dashboard;
- gets a new version with an upload, a
git pushorzeno --prod.
Storing data
Does your bot store data, such as warnings, levels or settings per server? Put it in the data folder the platform gives you through the environment variable ZENODEV_DATA_DIR, for example a SQLite database or a JSON file. That folder is kept when you deploy a new version; files anywhere else are not.
Troubleshooting
- “An invalid token was provided”. The environment variable is missing or has a different name than in your code. Check upper case and spaces, and deploy again.
- “Used disallowed intents”. Turn on the intents your bot uses, such as Message Content or Server Members, in the Developer Portal under Bot.
- The bot keeps starting and stopping. Check the logs: usually a package is missing from
package.jsonorrequirements.txt. - Your bot also has a web dashboard. Make the web server listen on the port from the
PORTenvironment variable. Your dashboard is then reachable athttps://your-bot.zeno-innovations.com.
Rather have a bot built?
Don't have a bot yet, or want one with AI, moderation and its own dashboard? Zeno Innovations builds them to order too, just like our own bot JARVIS. Have a look at Discord bot development.