Discord Bot Deployment
Deploy your Discord bot from local development to production. This guide covers code upload, dependency installation, secret management, and CI/CD automation.
Prerequisites
Section titled “Prerequisites”Before deploying, ensure you have:
- Discord bot application with a valid token from Discord Developer Portal
- Source code for Node.js (Discord.js, Eris, etc.) or Python (discord.py, Nextcord, etc.)
package.jsonorrequirements.txtfor dependency installation- Optional: Git repository with automated tests
Provision Your Container
Section titled “Provision Your Container”-
Sign in to panel.mambahost.com
-
Click Create Server → Discord Bot Hosting
-
Choose your plan (Starter/Pro/Premium) and region
-
Confirm the runtime (
node20+ or Python 3.11+) under Startup -
Adjust start command if your entry file differs (e.g.,
node dist/index.js) -
Enable backups in Settings → Backups
Upload Your Code
Section titled “Upload Your Code”Option 1: SFTP (Recommended)
Section titled “Option 1: SFTP (Recommended)”-
Get SFTP credentials from your panel
-
Connect using an SFTP client (FileZilla, WinSCP, etc.) on port 2022
-
Upload your repository to
/home/container -
Exclude build artifacts (
node_modules,.venv, etc.)
Option 2: Web File Manager
Section titled “Option 2: Web File Manager”- Drag-and-drop single files
- Upload a ZIP and extract in the panel
- Best for small updates
Option 3: Git + CI/CD
Section titled “Option 3: Git + CI/CD”- Build and test in GitHub Actions
- Sync artifacts via SFTP or panel API
- See CI/CD section below
Install Dependencies
Section titled “Install Dependencies”Node.js
Section titled “Node.js”npm install# orpnpm installUse lockfiles (package-lock.json, pnpm-lock.yaml) for reproducible builds.
Python
Section titled “Python”pip install -r requirements.txt# or for Poetrypip install .Native Packages
Section titled “Native Packages”Music bots often need FFmpeg and libsodium. Request these through support if not already installed.
Environment Variables & Secrets
Section titled “Environment Variables & Secrets”-
Navigate to Startup → Variables
-
Add your secrets:
DISCORD_TOKENAPPLICATION_ID- API keys (OpenAI, Stripe, etc.)
- Database credentials
- Webhook URLs
-
Mark sensitive values as hidden to prevent logging
-
Access in code:
Node.js const token = process.env.DISCORD_TOKEN;# Pythonimport ostoken = os.getenv("DISCORD_TOKEN")
Start and Validate
Section titled “Start and Validate”-
Click Start — the watchdog restarts automatically on crashes
-
Watch the console for gateway login confirmation
-
Test slash commands in your Discord server
-
Configure scheduled restarts (daily/weekly) for stability
-
Subscribe to incidents at status.mambahost.com
CI/CD Automation
Section titled “CI/CD Automation”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 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"}'Zero-Downtime Deployment
Section titled “Zero-Downtime Deployment”-
Keep a staging container synced with production
-
Deploy to staging first and run smoke tests
-
Register slash commands against the staging bot
-
Promote to production by switching tokens/env vars
Rollback Plan
Section titled “Rollback Plan”- Store the last good build in
/backupsor object storage - Use panel backups to revert files and env vars
- Restore database dumps before re-running migrations
Scaling & Sharding
Section titled “Scaling & Sharding”Discord.js Sharding
Section titled “Discord.js Sharding”const { ShardingManager } = require('discord.js');const manager = new ShardingManager('./bot.js', { totalShards: 'auto', token: process.env.DISCORD_TOKEN});manager.spawn();Python Auto-Sharding
Section titled “Python Auto-Sharding”- Disnake:
AutoShardedBot - Hikari: Built-in sharding support
Horizontal Scaling
Section titled “Horizontal Scaling”- Run multiple containers, each handling a portion of shards
- Coordinate via Redis or REST for shared state
- Allocate additional CPU (Premium) for voice-heavy bots
Backups & Recovery
Section titled “Backups & Recovery”-
Enable daily backups for the container filesystem
-
Verify restore points weekly
-
Schedule database exports (
mysqldumpor SQLite copies) to/backups -
Document recovery steps — token rotation, slash-command re-registration
Helpful Links
Section titled “Helpful Links”Need Help?
Section titled “Need Help?”- Support: support@mambahost.com
- Discord: Join our server