NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

How to deploy a discord.py bot to Schokr

Run a Python Discord bot 24/7 on Schokr: upload your code, list packages in requirements.txt, add a .env file and set the startup file.

Updated · 2 min read

To host a Python Discord bot on Schokr, create a server from the Python template, upload your code and a requirements.txt with the file manager, add your token in a .env file, set your main file in the server's Startup settings, and start the server.

Prepare your project

Your bot should already run locally. A typical layout:

my-bot/
  bot.py
  requirements.txt
  .env
  cogs/
    fun.py

requirements.txt lists every package the bot imports, one per line:

discord.py>=2.4
python-dotenv>=1.0
aiosqlite>=0.20

Package names don't always match import names. import dotenv comes from python-dotenv, and import discord comes from discord.py. If something is missing you'll see ModuleNotFoundError; see fixing module not found errors.

1. Create the server

  1. In the Schokr console, create a server from the Python template.
  2. Start with 256 to 512 MB of memory. A basic discord.py bot uses well under that.
  3. Pick any location; Discord bots aren't sensitive to it, but being near your database helps.

2. Upload the files

  1. Open the server's file manager.
  2. Upload your .py files, folders and requirements.txt. For many files, upload a zip and extract it in the file manager.
  3. Don't upload .venv, venv or __pycache__. Virtual environments aren't portable between machines, and the server installs packages itself.

3. Add your token

Create .env in the server root:

DISCORD_TOKEN=your-token-here

Load it in code with from dotenv import load_dotenv and load_dotenv() before reading os.environ["DISCORD_TOKEN"]. See storing your token safely.

4. Set the main file

Open your server's Startup settings and set the app or main file to your entry script, for example bot.py. If the template has a setting for a requirements file, make sure it points at requirements.txt.

5. Start the server

Start it and watch the console. The Python template is set up to install packages from your requirements file before launching the bot, so you'll see pip output first and then your on_ready message.

If you don't see pip install anything, check that requirements.txt is in the server root and that your Startup settings reference it.

Paths and working directory

The bot runs from the server's root folder. If you load files such as cogs or a database, build paths relative to your script so they work no matter where the process starts:

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent
DB_PATH = BASE_DIR / "data" / "bot.db"

For cogs inside a cogs folder, load them in setup_hook with await bot.load_extension("cogs.fun").

Output not showing in the console?

Python buffers output when it isn't attached to a terminal, so print() lines can appear late. Use print(..., flush=True) or, better, the logging module. discord.py sets up logging automatically when you start it with bot.run(). See reading bot logs.

Updating the bot

Upload the changed files and restart. If you added a package, add it to requirements.txt first. See updating your bot's code.

Still stuck?

Post the console error (with your token removed) in the Schokr Discord.