Deploy Discord Bot
Discord bot with modern slash commands,Music app,Chatgpt & more
Discord-Bot-Template
Just deployed
MongoDB
Just deployed
/data/db
Deploy and Host Discord Bot on Railway
A Discord Bot is an automated application that interacts with users and servers through Discord. This template provides a feature-rich starting point with modern slash commands, including ChatGPT integration, a music player, Tic Tac Toe, an auto-generated help command, and error logging for unexpected issues.
About Hosting Discord Bot
Hosting the Discord Bot on Railway requires running the bot application alongside a MongoDB database. The bot uses Discord credentials and an OpenAI API key for its integrations, while MongoDB provides persistent application data storage. Railway can run both services within the same project, with the bot connecting to MongoDB through private service networking. MongoDB requires a persistent volume mounted at /data/db so database data survives restarts and redeployments. Since the bot operates through Discord rather than serving a web application, it does not require a public HTTP domain or exposed web port. Railway handles the underlying service infrastructure while keeping the bot and database easy to manage together.
Common Use Cases
- Building interactive Discord communities with slash commands, games, and music
- Adding ChatGPT-powered conversations to Discord servers
- Running community bots with automated help commands and error logging
Dependencies for Discord Bot Hosting
- Discord application and bot token
- OpenAI API key
- MongoDB database
- Discord application client ID
- Discord administrator user ID
Deployment Dependencies
- Discord Developer Portal
- OpenAI API Platform
- MongoDB Docker Image
- Discord Bot Template Repository
- Discord Bot Template Wiki
Implementation Details
The bot requires the following environment variables:
| Variable | Required | Description |
|---|---|---|
BOT_TOKEN | Yes | Discord bot token obtained from the Discord Developer Portal |
CLIENT_ID | Yes | Discord application client ID |
OPEN_AI_KEY | Yes | OpenAI API key |
ADMIN_USER_ID | Yes | Discord user ID of the administrator used for unexpected error notifications |
MONGO_URI | Yes | MongoDB connection string used by the bot |
Raw Editor example:
BOT_TOKEN=your_discord_bot_token
CLIENT_ID=your_discord_application_client_id
OPEN_AI_KEY=your_openai_api_key
ADMIN_USER_ID=your_discord_user_id
MONGO_URI=mongodb://username:password:host:27017
Create a MongoDB service alongside the bot. The template uses MongoDB 7.0:
mongo:7.0
MongoDB requires persistent storage mounted at:
/data/db
In Railway, open the MongoDB service, go to Settings → Volumes, add a volume, and use /data/db as the mount path.
MongoDB uses TCP port 27017 for connections from the bot service. The bot does not require a public HTTP port or Railway domain.
The MongoDB service should provide the connection details used by MONGO_URI, including the database hostname, port, username, and password. Use Railway's private service networking for the bot-to-database connection.
No custom build or start commands are documented in the provided template.
Why Deploy 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 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
Discord-Bot-Template
OnCloud125252/Discord-Bot-TemplateBOT_TOKEN
your_discord_bot_token
CLIENT_ID
your_discord_application_client_id
OPEN_AI_KEY
your_openai_api_key
ADMIN_USER_ID
your_discord_user_id
MongoDB
mongo:8.0