---
title: "Deploy Discord LLM Bot"
description: "Discord LLM bot with memory and search that finds meaning, not words."
category: "Bots"
url: https://railway.com/deploy/PVL8qm
---

# Deploy Discord LLM Bot

Discord LLM bot with memory and search that finds meaning, not words.

**[Deploy Discord LLM Bot on Railway](https://railway.com/template/PVL8qm)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/PVL8qm/manifest.json

- **Creator:** Mark Chen's Projects
- **Category:** Bots
- **Total deploys:** 104

## Template content

### Discord-Bot

- **Source:** yuting1214/Discord-Bot
- **Public domain:** Yes

### PostgresSearch https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/yuting1214/postgres-search:0.4.0

## Documentation

# Deploy and Host a Discord LLM Bot on Railway

A Discord chatbot that remembers your conversations and can find them again —
by exact words *or* by what they were about, in any of 30+ languages. Two
services, no search cluster, no vector database to run alongside.

Built with [discord.py](https://discordpy.readthedocs.io/), FastAPI and
PostgreSQL. Works with OpenAI or OpenRouter, and the model is a setting rather
than something baked into the code.

## About Hosting a Discord LLM Bot

A Discord bot has to stay connected, so it is always-on by nature — which makes
the size of what you leave running the whole cost story. This template deploys
**two** services: the bot, and a PostgreSQL that does the searching itself
through [PostgreSQL + Hybrid Search](https://railway.com/deploy/postgresql-hybrid-search?referralCode=jk_FgY&utm_medium=integration&utm_source=template&utm_campaign=generic).
No Meilisearch container, no vector database, no sync job between them.

Everything the bot needs is provisioned on first boot: the schema, the search
extensions and the text analyzer. Existing deployments upgrade in place — new
columns are added on startup, so there is no migration to run and nothing to
back up first.

You bring a Discord bot token and one API key. **No privileged intents are
required**, so there is nothing to enable in the Developer Portal and no
approval to wait for.

## Why Deploy a Discord LLM 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 LLM 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.

Specific to this template:

- **The database is a template too**, so the search engine underneath is
  maintained and versioned separately from the bot.
- **One file configures the bot.** `config/bot.yaml` holds the persona, the
  provider, the model and the search tuning. Environment variables still
  override it, so you can retune a running service from the Railway dashboard
  without a rebuild.
- **Costs stay proportional to conversations, not messages.** The bot writes one
  summary per session rather than embedding every message you send.
- **Token usage is recorded per session**, so you can see what the bot actually
  costs you.

## Common Use Cases

- A team assistant in a shared channel, where everyone contributes to one thread
  and anyone can search it afterwards
- A support or study bot whose history stays searchable months later — "what did
  we decide about the deploy script?" finds the conversation even when you have
  forgotten the words used
- A multilingual community bot: Chinese, Japanese, Korean, Thai and 30+ more are
  segmented properly, not treated as one long token
- A private research assistant, where each person's history is searchable only
  by them

## User Manual

All commands are Discord **slash commands** — type `/` and Discord will list
them with descriptions.

### Talking to the bot

| | Command | What it does |
|---|---|---|
| 1 | `/start_session` | Starts a **new** private conversation. Your previous one is closed and summarised. |
| 2 | `/bot` | Continues your current private conversation, with the last few turns replayed as memory. |
| 3 | `/start_group_session` | Starts a **new** shared conversation for the whole channel. |
| 4 | `/bot_group` | Continues the channel's shared conversation — anyone can contribute. |

> **Example** — `/start_session` `message:` *How do I brine a turkey?*
> then `/bot` `message:` *and how long should it rest?*

### Finding it again

| | Command | What it does |
|---|---|---|
| 5 | `/search` | Searches **your own** history in this channel. |
| 6 | `/search_group` | Searches the **channel's shared** history. |

Search works two ways at once. Exact words find what you typed; meaning finds
the conversation even when you use none of the original words — so
*"preserving vegetables with salt"* finds the one about kimchi. If nothing
matches, it says so rather than guessing.

Results show the session id and how many matched.

> **Example** — `/search` `query:` *turkey brine*

### Picking up where you left off

| | Command | What it does |
|---|---|---|
| 7 | `/resume_session` | Reopens one of your previous private conversations. |
| 8 | `/resume_group_session` | Reopens a previous shared conversation. |

Copy the `session_id` from any search result and pass it in. The bot regains the
context of that conversation and carries on.

> **Example** — `/resume_session` `session_id:` *52e9d6ce-7fda-462c-9983-71fa6bedf6c4*

### Getting started after deploy

1. Invite the bot with the `bot` and `applications.commands` scopes.
2. Run `/start_session` in any channel.

Slash commands can take a minute to appear the first time Discord registers
them.

## Dependencies for a Discord LLM Bot

- A **Discord bot token** — [Developer Portal](https://discord.com/developers/applications)
  → Applications → Bot → Token
- An **OpenAI API key**, or an OpenRouter key if you set `LLM_PROVIDER=openrouter`
- **PostgreSQL + Hybrid Search**, deployed alongside the bot

### Deployment Dependencies

- [Discord Developer Portal](https://discord.com/developers/applications) — create the application and bot
- [OpenAI API keys](https://platform.openai.com/api-keys) or [OpenRouter](https://openrouter.ai/keys)
- [PostgreSQL + Hybrid Search](https://railway.com/deploy/postgresql-hybrid-search?referralCode=jk_FgY&utm_medium=integration&utm_source=template&utm_campaign=generic) — the database this template deploys
- [Source code and changelog](https://github.com/yuting1214/Discord-Bot)

### Implementation Details

Search combines two rankings rather than blending two scores. BM25 covers the
exact words and is maintained by the database itself as messages arrive — no API
call and no delay. Meaning comes from one embedding per session, written when a
session ends, which keeps embedding cost proportional to conversations rather
than keystrokes. Each side decides for itself whether it matched before the two
are merged, which is why an unrelated query returns nothing at all.

## Learn More

- [discord.py](https://discordpy.readthedocs.io/en/stable/)
- [OpenRouter reasoning](https://openrouter.ai/docs/use-cases/reasoning-tokens)
- [Changelog](https://github.com/yuting1214/Discord-Bot/blob/main/CHANGELOG.md)


## Similar templates

- [Telegram JavaScript Bot](https://railway.com/deploy/5lRkWa) — A template for Telegram bot in JavaScript using grammY
- [Cobalt Tools [Updated Oct ’26]](https://railway.com/deploy/cobalt) — Cobalt Tools [Oct ’26] (Media Downloader, Converter & Automation) Self Host
- [Telegram Gateway](https://railway.com/deploy/railway-telegram-gateway) — Multi-bot Telegram webhook gateway with WebSocket event streaming

Open this page in a browser: https://railway.com/deploy/PVL8qm
