Guide

How to host a discord.py bot

Most bots that fail on a host fail for the same few reasons: a token pasted into the code, a missing dependency, or the wrong start file. Fix those first and hosting anywhere becomes easy.

6 minute read

1. Read the token from the environment

Never write your token into the file. Read it from an environment variable instead, so the same code works on your PC and on a server without the secret ever being saved in your code.

import os
import discord

intents = discord.Intents.default()
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f"Logged in as {client.user}")

TOKEN = os.environ.get("BOT_TOKEN")
if not TOKEN:
    raise SystemExit("BOT_TOKEN is not set")

client.run(TOKEN)

On your own machine you can set it for one session:

# macOS / Linux
export BOT_TOKEN="your-token-here"
python bot.py

# Windows PowerShell
$env:BOT_TOKEN = "your-token-here"
python bot.py

2. Write a requirements.txt

A host installs your dependencies from this file. If a package is missing from it, the bot works on your PC and crashes on the server with ModuleNotFoundError.

discord.py
python-dotenv

Add every package you import that is not part of Python itself. Pinning versions, such as discord.py==2.4.0, stops an update from breaking the bot unexpectedly.

3. Check the privileged intents

If your bot reads message content or member lists, you must enable those intents in two places: in your code, and in the Discord Developer Portal under your application's Bot settings. Forgetting the portal side is one of the most common reasons a bot connects but ignores every command.

4. Know your start file

Hosts run one file to start your bot. It is usually bot.py or main.py. If your project starts from a different file, make sure the host is told which one.

5. Test it clean

Before uploading, prove the bot starts from nothing:

python -m venv test-env
# macOS / Linux
source test-env/bin/activate
# Windows
test-env\Scripts\activate

pip install -r requirements.txt
python bot.py

If it starts here, it will start on a host. If it fails, the error tells you exactly which package is missing.

Deploying it on SnowServers

  1. Choose a plan on the Discord bots page. Flurry, at 1 GB, is plenty for most bots.
  2. In the Startup tab, paste your token into Bot token.
  3. Put your code on: upload your files and requirements.txt in Files (or over SFTP), or paste your GitHub repository link into Git repository on the Startup tab.
  4. Press Restart on the Console page. The console shows the dependencies installing, which file it started, and then your bot's own output.

Dependencies are installed again whenever requirements.txt changes, so adding a package is just editing that file and restarting. The Python version, 3.10 to 3.14, is under Docker Image. The first-bot walkthrough in our docs goes through it button by button.

Common errors

  • ModuleNotFoundError: the package is missing from requirements.txt.
  • LoginFailure: Improper token: the token is wrong, has spaces around it, or was regenerated.
  • Bot is online but ignores commands: privileged intents are off in the Developer Portal.
  • Works for a while, then stops: check the console for an unhandled exception. A host restarts the process, but a bug that crashes on every event will keep crashing.