Railway

Deploy Discord Bot | Python Starter That Builds, discord.py 2.7

Discord bot starter that builds: current discord.py, pinned Python.

Deploy Discord Bot | Python Starter That Builds, discord.py 2.7

discordpy-railway-starter

ak40u/discordpy-railway-starter

Just deployed

Deploy and Host a Discord Bot on Railway

A minimal Discord bot written with discord.py — a working starting point you extend, rather than a demo that has to be repaired first.

About Hosting a Discord Bot

A Discord bot is a long-running process that holds a websocket to Discord's gateway. It has no HTTP endpoint and no public URL, so hosting it means keeping a worker alive, restarting it when it dies, and giving it a token through the environment rather than the source tree. That is the whole job, and it is where a starter earns its keep: the dependency set has to still install, and the failure messages have to tell you which of the three usual mistakes you made.

Common Use Cases

  • A moderation or utility bot for your own server
  • A notification bot that posts build results, alerts, or scheduled digests into a channel
  • A starting point for a larger bot you intend to grow

Dependencies for Discord Bot Hosting

  • discord.py~=2.7.1 — declared as the only direct dependency, so pip resolves the rest against the Python you actually run

Deployment Dependencies

Implementation Details

The long-standing discord.py starter on Railway freezes its entire 2022 transitive tree — aiohttp==3.8.3, frozenlist==1.3.3, yarl==1.8.2, multidict==6.0.3. None of those have wheels for Python 3.12 or newer, so pip compiles them from source, and the generated C uses CPython internals that were removed:

frozenlist/_frozenlist.c:8088:45: error: 'PyLongObject' has no member named 'ob_digit'
frozenlist/_frozenlist.c:7723:27: error: too few arguments to function '_PyLong_AsByteArray'
error: command '/usr/bin/gcc' failed with exit code 1
ERROR: Failed building wheel for frozenlist

The build dies before the bot ever runs.

This template declares only discord.py and pins the runtime in .python-version, so pip installs current wheels and a future builder upgrade cannot move the interpreter underneath you.

The other two ways a Discord bot deployment fails are handled explicitly rather than as a traceback:

  • a missing DISCORD_TOKEN exits with a message naming the variable and where to get it
  • a rejected token and a missing Message Content intent each print what to fix and where

Getting Started

  1. Create an application in the Discord Developer Portal.
  2. Under Bot, reset the token and copy it into the DISCORD_TOKEN variable.
  3. Under Bot → Privileged Gateway Intents, enable Message Content Intent.
  4. Under OAuth2 → URL Generator, select the bot scope, grant Send Messages, and open the generated URL to invite it.

Send !ping in any channel the bot can see. Add your own commands in main.py.

Why Deploy a Discord Bot on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying a Discord bot on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


Template Content

discordpy-railway-starter

ak40u/discordpy-railway-starter

More templates in this category

View Template
Telegram JavaScript Bot
A template for Telegram bot in JavaScript using grammY

Agampreet Singh
295
View Template
Cobalt Tools [Updated Jul ’26]
Cobalt Tools [Jul ’26] (Media Downloader, Converter & Automation) Self Host

shinyduo
248
View Template
Telegram Gateway
Multi-bot Telegram webhook gateway with real-time WebSocket event streaming

INAPP
5