Railway

Deploy Discord LLM Bot

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

Deploy Discord LLM Bot

Just deployed

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.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

CommandWhat it does
1/start_sessionStarts a new private conversation. Your previous one is closed and summarised.
2/botContinues your current private conversation, with the last few turns replayed as memory.
3/start_group_sessionStarts a new shared conversation for the whole channel.
4/bot_groupContinues 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

CommandWhat it does
5/searchSearches your own history in this channel.
6/search_groupSearches 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

CommandWhat it does
7/resume_sessionReopens one of your previous private conversations.
8/resume_group_sessionReopens 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 tokenDeveloper 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

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

More templates in this category

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

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

shinyduo
279
View Template
Telegram Gateway
Multi-bot Telegram webhook gateway with WebSocket event streaming

INAPP
5