Discord Bot Deployment
Use this runbook to take a Discord bot from local development to a production-grade deployment on Mamba Host. It covers provisioning, code delivery, dependency installs, secret management, CI/CD automation, scaling, and recovery strategies.
Prerequisites
Section titled “Prerequisites”- Discord bot application with a valid token from https://discord.com/developers/applications.
- Source code written for Node.js (Discord.js, Eris, Oceanic, etc.) or Python (discord.py, Nextcord, Py-cord, Disnake, Hikari, etc.).
package.jsonorrequirements.txt(or Poetry/Pipenv lockfiles) so dependencies can be installed reproducibly.- Optional: Dockerfile/build script if you precompile native modules locally.
- Optional: Git repository with automated tests (Vitest/Jest/PyTest) and linting before deploy.
1. Provision the Container
Section titled “1. Provision the Container”- Sign in to https://panel.mambahost.com.
- Click Create Server → Discord Bot Hosting.
- Choose the appropriate plan (Starter/Pro/Premium) and region (Texas by default).
- Confirm the runtime (
node20+, Python 3.11+) under Startup. Adjust the start command if your entry file differs (e.g.,node dist/index.js). - Enable automatic backups (Settings → Backups) so code and configs can roll back quickly.
2. Upload Code
Section titled “2. Upload Code”- SFTP (recommended): Use the credentials in SFTP Settings (port 2022) and upload your repository to
/home/container. Excludenode_modules,.venv, or other build artifacts to keep deploys lightweight. - Web File Manager: Drag-and-drop single files or upload a ZIP and extract it in the panel.
- Git-based workflows: Run builds/tests in GitHub Actions, then sync artifacts via SFTP or the panel API (see CI/CD section).
Ensure your entry file (index.js, bot.py, etc.) is at the root or adjust the STARTUP_CMD.
3. Install Dependencies
Section titled “3. Install Dependencies”- Node.js:
npm installorpnpm installfrom the panel console. Use lockfiles to keep versions deterministic. - Python:
pip install -r requirements.txt(orpip install .for Poetry exports). - Native/system packages: music bots often need FFmpeg + libsodium. Request these packages through support if they are not already installed.
- Binary assets: download
yt-dlp, uwuifier libs, or other binaries in a post-deploy script and schedule it via the panel if needed.
4. Manage Environment Variables & Secrets
Section titled “4. Manage Environment Variables & Secrets”- Go to Startup → Variables.
- Add entries for
DISCORD_TOKEN,APPLICATION_ID, API keys (OpenAI, Stripe, etc.), database credentials, webhook URLs, and feature flags. - Mark sensitive values as hidden to prevent accidental logging.
- Reference secrets via
process.env.MY_SECRET(Node.js) oros.getenv("MY_SECRET")(Python). Never commit secrets to git.
5. Start, Validate, Monitor
Section titled “5. Start, Validate, Monitor”- Click Start; watchdog restarts the process automatically if it exits with errors.
- Watch the live console for gateway login confirmation.
- Test slash commands/interactions inside your Discord server.
- Configure scheduler-based restarts (daily/weekly) and script tasks such as dependency updates or data exports.
- Subscribe to incidents at https://status.mambahost.com or send alerts to your Discord via webhook.
6. Optional Add-Ons
Section titled “6. Optional Add-Ons”- Managed MySQL: available on Pro/Premium plans; request credentials and add them as env vars.
- Multiple bots per container: spawn child processes or PM2-managed scripts with dedicated env vars (
BOT1_TOKEN,BOT2_TOKEN, etc.). - External services: connect to Redis/Upstash for caching, S3-compatible storage for assets, or third-party APIs (OpenAI, Anthropic, etc.) using env vars.
7. CI/CD Automation
Section titled “7. CI/CD Automation”Integrate deploys with your repo to avoid manual uploads.
GitHub Actions Example
Section titled “GitHub Actions Example”name: Deploy Boton: push: branches: [ main ]
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: npm ci - run: npm test - name: Upload via SFTP uses: wlixcc/SFTP-Deploy-Action@v1.2 with: server: ${{ secrets.SFTP_HOST }} username: ${{ secrets.SFTP_USER }} password: ${{ secrets.SFTP_PASS }} port: 2022 local-path: "./" remote-path: "/home/container" exclude: "node_modules,.git" - name: Restart bot via Panel API run: | curl -X POST "https://panel.mambahost.com/api/client/servers/${{ secrets.SERVER_ID }}/power" \ -H "Authorization: Bearer ${{ secrets.PANEL_API_KEY }}" \ -H "Content-Type: application/json" \ -d '{"signal":"restart"}'Request a Panel API key from support if you want to automate start/stop/restart actions.
Zero-Downtime Strategy
Section titled “Zero-Downtime Strategy”- Keep a staging container synced with production.
- Deploy to staging, run smoke tests, and register slash commands against the staging bot.
- Promote by switching tokens/env vars or by scaling staging to production hardware while leaving the prior version on standby.
Rollback Plan
Section titled “Rollback Plan”- Store the last good build inside
/backupsor an object store. - Use panel backups to revert both files and env vars.
- Restore database dumps (MySQL/SQLite) before re-running migrations.
8. Scaling & Sharding
Section titled “8. Scaling & Sharding”- Discord.js:
new ShardingManager('./bot.js', { totalShards: 'auto', token: process.env.DISCORD_TOKEN })on Pro/Premium tiers. - Disnake/Hikari: leverage auto-sharding or spawn multiple worker processes.
- Horizontal scaling: run multiple containers, each handling a portion of shards; coordinate via Redis or REST for shared state.
- Voice-heavy bots: allocate additional CPU (Premium) and request FFmpeg/sodium libs to minimize latency.
9. Backups & Disaster Recovery
Section titled “9. Backups & Disaster Recovery”- Enable daily backups for the container filesystem and verify restore points weekly.
- Schedule cron tasks to export SQLite or
mysqldumpresults into/backups. - Mirror logs to object storage or an external SIEM if you need longer retention.
- Document manual steps (token rotation, slash-command re-registration, notifying users).
Troubleshooting
Section titled “Troubleshooting”- Bot stuck on “Connecting” – Confirm the token, gateway intents, and privileged-intent approvals. Regenerate tokens if leaked.
- Out-of-memory errors – Reduce cache size, limit shards, or upgrade plans; look for
heap out of memory/MemoryErrorin logs. - Audio playback issues – Ensure FFmpeg and libsodium are installed; verify the bot has permissions to join/speak in target channels.
- Python wheel build failures – Pre-build wheels locally (
pip wheel -r requirements.txt) and upload, or request required apt packages from support. - Rate limit spam – Implement request queuing/backoff, respect Discord rate-limit headers, and centralize API calls instead of scattering them per shard.
- Watchdog restart loops – Check exit codes, review console output, and replicate locally or in staging before redeploying.
Need help? Email support@mambahost.com or open a Discord ticket with logs/steps-to-reproduce.