Skip to content

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.

  • 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.json or requirements.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. Sign in to https://panel.mambahost.com.
  2. Click Create Server → Discord Bot Hosting.
  3. Choose the appropriate plan (Starter/Pro/Premium) and region (Texas by default).
  4. Confirm the runtime (node 20+, Python 3.11+) under Startup. Adjust the start command if your entry file differs (e.g., node dist/index.js).
  5. Enable automatic backups (Settings → Backups) so code and configs can roll back quickly.
  • SFTP (recommended): Use the credentials in SFTP Settings (port 2022) and upload your repository to /home/container. Exclude node_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.

  • Node.js: npm install or pnpm install from the panel console. Use lockfiles to keep versions deterministic.
  • Python: pip install -r requirements.txt (or pip 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.
  1. Go to Startup → Variables.
  2. Add entries for DISCORD_TOKEN, APPLICATION_ID, API keys (OpenAI, Stripe, etc.), database credentials, webhook URLs, and feature flags.
  3. Mark sensitive values as hidden to prevent accidental logging.
  4. Reference secrets via process.env.MY_SECRET (Node.js) or os.getenv("MY_SECRET") (Python). Never commit secrets to git.
  1. Click Start; watchdog restarts the process automatically if it exits with errors.
  2. Watch the live console for gateway login confirmation.
  3. Test slash commands/interactions inside your Discord server.
  4. Configure scheduler-based restarts (daily/weekly) and script tasks such as dependency updates or data exports.
  5. Subscribe to incidents at https://status.mambahost.com or send alerts to your Discord via webhook.
  • 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.

Integrate deploys with your repo to avoid manual uploads.

name: Deploy Bot
on:
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.

  1. Keep a staging container synced with production.
  2. Deploy to staging, run smoke tests, and register slash commands against the staging bot.
  3. Promote by switching tokens/env vars or by scaling staging to production hardware while leaving the prior version on standby.
  • Store the last good build inside /backups or an object store.
  • Use panel backups to revert both files and env vars.
  • Restore database dumps (MySQL/SQLite) before re-running migrations.
  • 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.
  • Enable daily backups for the container filesystem and verify restore points weekly.
  • Schedule cron tasks to export SQLite or mysqldump results 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).
  • 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/MemoryError in 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.