A Node.js application that bridges communication between a MUD (Multi-User Dungeon) and Discord channels, enabling bidirectional chat relay.
- π Bidirectional message relay between MUD and Discord
- π Multiple channel mapping support
- π Automatic reconnection with configurable retry logic
- π« Security features (@everyone/@here mention stripping)
- β‘ Rate limiting to prevent spam
- π Optional MUD authentication support
- π Emoji stripping for MUD compatibility
- π Winston logging with rotation and multiple outputs
- π₯ Health check endpoint for monitoring
- π Graceful shutdown handling
- π³ Docker containerization support
- π¦ PM2 support for production deployment
- Clone the repository:
git clone https://github.com/LuminariMUD/discord-mud-chat.git
cd discord-mud-chat- Install dependencies:
npm install-
Configure the application:
- Copy
config/config.example.jsontoconfig/config.json - Edit
config/config.jsonwith your MUD connection details and channel mappings - Copy
.env.exampleto.env - Add your Discord bot token to
.env
- Copy
-
Run the application:
npm start # Production mode
npm run dev # Development mode with auto-restartFor detailed installation and deployment instructions, see π Deployment Guide.
- Visit the Discord Developer Portal and create a new application
- Record the Client ID (you'll need this for the invite URL)
- Navigate to the Bot section in the left sidebar
- Click Reset Token and record the token for later use
- Under Privileged Gateway Intents, enable:
- Server Members Intent
- Message Content Intent
- Use this URL, replacing
CLIENT_IDwith your Client ID:https://discord.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot&permissions=3072 - Select your server and authorize the bot
- Enable Developer Mode in Discord (Settings β Advanced β Developer Mode)
- Right-click on any channel you want to bridge
- Select Copy ID
Create a .env file in the project root:
# Required
DISCORD_TOKEN=your_discord_bot_token_here
# Optional
# MUD_AUTH_TOKEN=your_mud_auth_token_here # For MUD authentication
# HEALTH_PORT=3000 # Health check endpoint port
# LOG_LEVEL=info # Logging level (error, warn, info, debug)Copy config/config.example.json to config/config.json and customize:
{
"mud_name": "LuminariMUD",
"mud_ip": "127.0.0.1",
"mud_port": 8181,
"mud_auth_token": "",
"mud_retry_count": 5,
"mud_retry_delay": 30000,
"rate_limit_per_channel": 10,
"strip_emoji": true,
"enable_bitly": false,
"largest_printable_string": 65535,
"channels": [
{ "discord": "432623057706811394", "mud": "gossip" },
{ "discord": "819275737328386118", "mud": "auction" },
{ "discord": "716021506605318195", "mud": "gratz" }
]
}| Option | Description | Default |
|---|---|---|
mud_name |
Display name for your MUD | Required |
mud_ip |
MUD server IP address | Required |
mud_port |
MUD server port | Required |
mud_auth_token |
Optional authentication token for MUD | "" |
mud_retry_count |
Number of reconnection attempts | 5 |
mud_retry_delay |
Delay between reconnection attempts (ms) | 30000 |
rate_limit_per_channel |
Messages per second per channel | 10 |
strip_emoji |
Remove emojis from messages | true |
enable_bitly |
Reserved for future use | false |
largest_printable_string |
Maximum message length | 65535 |
channels |
Array of channel mappings | Required |
The application exchanges JSON messages with the MUD:
{
"channel": "String", // MUD channel name
"name": "String", // Username/player name
"message": "String", // Chat message content
"emoted": 0 // Optional: 1 for emote messages
}npm start # Production mode
npm run dev # Development mode with auto-restartdocker-compose up -dpm2 start ecosystem.config.jsFor detailed deployment instructions including:
- Local installation and configuration
- Docker deployment with compose
- PM2 process management
- Production best practices
- Security hardening
- Monitoring and health checks
- Troubleshooting guide
See the complete π Deployment Guide
npm start- Start the applicationnpm run dev- Start with nodemon for developmentnpm run lint- Run ESLint to check code qualitynpm run lint:fix- Run ESLint with auto-fix
- Verify your Discord token in
.envis correct - Check that the bot has been invited to your server
- Ensure the bot has proper permissions in the target channels
- Check console output for specific error messages
- Verify the MUD IP and port in
config/config.json - Ensure the MUD server is running and accepting connections
- Check firewall settings on both client and server
- Review console logs for connection errors
- Confirm channel IDs in
config/config.jsonare correct - Verify the bot can see and send messages in the Discord channels
- Check that MUD channel names match exactly (case-sensitive)
- Ensure Message Content Intent is enabled in Discord Developer Portal
- Adjust
mud_retry_delayfor less frequent reconnection attempts - Monitor message volume and adjust
largest_printable_stringif needed - Consider using PM2 for better process management and auto-restart
mud-discord-chat/
βββ src/
β βββ index.js # Main application file
β βββ logger.js # Winston logging configuration
β βββ health.js # Health check HTTP server
βββ config/
β βββ config.json # Your configuration (git ignored)
β βββ config.js # Configuration loader
β βββ config.example.json # Configuration template
βββ docs/
β βββ deploy.md # Comprehensive deployment guide
β βββ bridge_requires.md # Technical requirements specification
β βββ mud_example/ # Example MUD integration code
βββ logs/ # Log files directory (auto-created)
βββ .env # Environment variables (git ignored)
βββ .env.example # Environment template
βββ .eslintrc.json # ESLint configuration
βββ ecosystem.config.js # PM2 configuration
βββ Dockerfile # Docker container definition
βββ docker-compose.yml # Docker Compose configuration
βββ .dockerignore # Docker ignore patterns
βββ CLAUDE.md # Claude Code guidance file
βββ LICENSE.txt # ISC License
βββ package.json # Project dependencies
βββ README.md # This file
The application uses Winston for comprehensive logging:
- Console output with colored formatting in development
- File logs with automatic rotation (7 days retention, 10MB max size)
logs/app.log- All application logslogs/error.log- Error logs onlylogs/pm2-*.log- PM2-specific logs (when using PM2)
Log levels can be configured via LOG_LEVEL environment variable (error, warn, info, debug).
Monitor application health at http://localhost:3000/health:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z",
"uptime": 3600,
"connections": {
"mud": true,
"discord": true
},
"messages": {
"mudToDiscord": 150,
"discordToMud": 200
}
}Issues and pull requests are welcome at https://github.com/LuminariMUD/discord-mud-chat
ISC License - See LICENSE file for details
