Discord Bot Starter (discord.py 2.7, Postgres)
A Python Discord bot starter on discord.py 2.7.1 that works once you paste a bot token: slash commands for help, latency, reminders and per-server tags, with state in Postgres. The template deploys the bot and a Railway Postgres 18 on the private network, ready to eject and extend with your own commands.
What you get
- A Bot service built from the template repository: python:3.13.18-slim-trixie pinned by digest, discord.py 2.7.1 and asyncpg 0.32.0, with every dependency pinned
- PostgreSQL 18.6 with a volume; the bot creates its tables on first start
- Slash commands /help, /ping, /about, /remind and /tag, using default intents only
- A private /healthz endpoint for Railway's healthcheck and no public domain
- A service that stays up and logs what to fix when the token is missing or rejected, instead of crash-looping
- Command sync with Discord only when the commands change, and DISCORD_GUILD_ID for instant updates in one server
Good for
- A community bot with FAQ tags such as /tag show rules and personal reminders
- A starting point for moderation helpers, role menus or integrations with your own APIs
- A bot that calls other services in your Railway project over the private network
Cost
Measured on Railway: the bot idles at about 55 MB RAM and Postgres at about 100 MB, both near 0 vCPU. The Trial plan is enough. The template author estimates roughly $1 to $2 a month.
Services in this template
- Bot · from
baranberkay96/discord-bot-railway - Postgres · image
ghcr.io/railwayapp-templates/postgres-ssl:18.6@sha256:4fc833b43d2aaf6ecc9b18615f5533602b723a32d0e2efe2dae8ca0f7217c863
Questions people ask
How do I connect it to Discord?
In the Discord Developer Portal, create an application, open Bot, click Reset Token and paste the token into DISCORD_TOKEN, then redeploy if you set it after deploying. The log prints Logged in as and, while the bot is in no server, an invite link with the bot and applications.commands scopes. Global slash commands can take a few minutes to appear the first time.
Are reminders and tags kept across redeploys?
Yes. They are stored in Postgres on a Railway volume. The Bot service itself has no volume and keeps no state.
How do I add my own commands?
Use Eject in the Bot service's settings so Railway copies the repository to your GitHub account. Add a module under app/cogs/ with an async def setup(bot) function, list it in EXTENSIONS in app/bot.py, and add tables to SCHEMA in app/db.py. Pushing to your repository redeploys.
Can I run more than one replica, and how do I upgrade?
Run one replica: a second copy with the same token would answer every command twice. Very large bots need discord.py's sharding (AutoShardedBot). Versions are pinned in services/bot/requirements.txt and the Dockerfile; change them there to upgrade.
What is not allowed?
Bots must follow Discord's Developer Terms of Service and Developer Policy. Selfbots with user tokens, music bots that stream from YouTube, spam and mass-DM tools are not part of the template and are not allowed by Discord or Railway's Fair Use Policy. discord.py is MIT-licensed, and this is a community template, not affiliated with Discord, the discord.py project or Railway.
Full template README
Deploy and Host Discord Bot Starter with Railway
A Python Discord bot that works as soon as you paste its token: slash commands for help, latency, reminders and per-server tags, with state in Postgres so nothing is lost on redeploy. Built on discord.py 2.7 with no privileged intents. It is a starter: eject the repo and add your own commands.
About Hosting Discord Bot Starter
A Discord bot is a long-running process that keeps a WebSocket connection to Discord's gateway and answers slash commands. It needs no public port, but it must stay online, reconnect after network blips, and keep its data somewhere safer than the container disk. This community template runs the bot from a pinned Python 3.13 image with every dependency pinned, connects it to a Railway Postgres over the private network, and creates its tables on first start. Slash commands are registered with Discord only when they change. A small private /healthz endpoint answers Railway's healthcheck, and a missing or wrong token is logged clearly instead of crash-looping the deploy.
Common Use Cases
- A community bot with FAQ tags (
/tag show rules) and personal reminders - A starting point for your own commands: moderation helpers, role menus, integrations with your APIs
- A bot that talks to other services in your Railway project over the private network
- Learning discord.py with a deployment that already handles reconnects, health and storage
Dependencies for Discord Bot Starter Hosting
- A Discord application with a bot user and its token
- The Bot service (built from this repo, Python 3.13, discord.py 2.7.1, asyncpg)
- Postgres 18 (Railway's
postgres-sslimage) with a volume
Deployment Dependencies
- Discord Developer Portal
- discord.py documentation
- discord.py on GitHub
- Discord Developer Terms of Service
- Railway Fair Use Policy
Implementation Details
| Service | What runs inside | Volume | Port |
|---|---|---|---|
| Bot | discord.py 2.7.1 bot (python -m app), private /healthz |
none | 8080, private (healthcheck only) |
| Postgres | PostgreSQL 18 (reminders, tags, command-sync state) | /var/lib/postgresql/data |
5432, private |
First start
- In the Developer Portal, create an application, open Bot, click Reset Token and copy it.
- Paste it into
DISCORD_TOKENwhen you deploy (or later on the Bot service, then redeploy). - The deploy log prints
Logged in as ...and, while the bot is in no server yet, an invite link. Open it to add the bot to your server (scopesbotandapplications.commands). - Type
/in your server. Global commands can take a few minutes to appear the first time; setDISCORD_GUILD_IDto your server id for instant updates while developing.
Commands included
| Command | What it does |
|---|---|
/help |
Lists all commands |
/ping |
Gateway latency and a database round trip |
/about |
Uptime, server count, versions |
/remind me when message |
Reminds you in the channel after 10m, 1h30m, 2d (up to 365 days, 25 per user); survives redeploys |
/remind list, /remind cancel |
Your pending reminders |
/tag set, /tag show, /tag list, /tag delete |
Saved snippets per server; creators or members with Manage Messages can edit and delete |
The bot uses only default intents, so nothing has to be enabled under Privileged Gateway Intents. Mentions in repeated text are disabled; reminders ping only their author.
When something is wrong
If DISCORD_TOKEN is empty or Discord rejects it, the service stays up, /healthz reports not-configured or token-invalid, and the log says what to do. Fix the variable and redeploy. While Postgres starts, the bot waits and retries.
Extend it
The deployed code comes from this template's GitHub repo. To change it, use Eject in the Bot service's settings (Railway copies the repo to your GitHub account and deploys from it), then add a module under app/cogs/ with an async def setup(bot) function and list it in EXTENSIONS in app/bot.py. Tables go into SCHEMA in app/db.py. Pushing to your repo redeploys.
Scaling and versions
Run one replica: a second copy of the same token would answer every command twice. One bot process handles thousands of servers; very large bots need discord.py's sharding (AutoShardedBot). Versions are pinned in services/bot/requirements.txt and the Dockerfile (python:3.13.18-slim-trixie by digest); change them there to upgrade.
Resources
Measured on Railway: the bot idles at about 55 MB RAM and Postgres at about 100 MB, near 0 vCPU. Trial plan is enough; cost is roughly $1–2/month.
Not included, on purpose
No music or YouTube playback, no selfbot or user-token features, no mass-DM tools: they break Discord's or Railway's terms.
Why Deploy Discord Bot Starter on Railway?
Railway keeps the bot online, restarts it when it stops, and gives it a private Postgres in the same project, with logs and redeploys from Git in one place. You paste a token and have a working bot to build on. This is a community template, not affiliated with Discord or the discord.py project.
About Discord bot starter: videos, guide and all Discord bot starter templates
Guides for this template
View Discord Bot Starter (discord.py 2.7, Postgres) on railway.com
Similar templates
| Template | Category | DeploymentsDeploys |
|---|---|---|
Evolution API Deploy Evolution API on Railway. WhatsApp REST API. One click. | Bots | 6,429 |
ChatGPT-On-WeChat 🤖️ Deploy ChatGPT on WeChat in 2 steps! 🤖️ | Bots | 2,877 |
Discord Python Bot A simple Discord Bot written in Python | Bots | 2,719 |
Typebot (Atualizado) Typebot facilita a criação de chatbots avançados. | Bots | 2,607 |
Telegram Bot Python A simple Python Telegram bot built using the telebot | Bots | 2,396 |
DiscordJS bot A basic Discord bot written in JavaScript | Bots | 1,137 |
