Deploy Discord LLM Bot
Discord LLM bot with memory and search that finds meaning, not words.
Discord-Bot
Just deployed
PostgresSearch
Just deployed
/var/lib/postgresql/data
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, 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. 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.yamlholds 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_sessionmessage:How do I brine a turkey? then/botmessage: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 —
/searchquery: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_sessionsession_id:52e9d6ce-7fda-462c-9983-71fa6bedf6c4
Getting started after deploy
- Invite the bot with the
botandapplications.commandsscopes. - Run
/start_sessionin 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 → 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 — create the application and bot
- OpenAI API keys or OpenRouter
- PostgreSQL + Hybrid Search — the database this template deploys
- Source code and changelog
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
Template Content
Discord-Bot
yuting1214/Discord-BotPASSWORD
USER_NAME
DISCORD_TOKEN
OPENAI_API_KEY
PostgresSearch
ghcr.io/yuting1214/postgres-search:0.4.0