Deploying Your Bot
How to run your Discord bot in production.
On a Linux Server
- SSH into your server
- Clone your bot’s repo
- Set up Python and dependencies
sh
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -r requirements.txt- Set your environment variables (
.envor Doppler). Remember that.envis gitignored, so it will not be in the clone - Run:
sh
./run.shUsing a Process Manager
A bot needs to stay running and to come back after a reboot, so use systemd rather than a bare ./run.sh in a shell.
ini
Description=My Discord Bot
After=network-online.target
[Service]
Type=simple
User=bot
WorkingDirectory=/home/bot/my-bot
ExecStart=/home/bot/my-bot/run.sh
Restart=always
RestartSec=5
Environment=ENVIRONMENTS=production
Environment=LOG_LEVEL=INFO
[Install]
WantedBy=multi-user.targetsh
sudo systemctl enable --now my-bot
sudo systemctl status my-bot
journalctl -u my-bot -fWith Docker (Example)
dockerfile
FROM python:3.11
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENV ENVIRONMENTS=production
CMD ["python3", "src/main.py"]⚠️ WARNING
Don't bake
.env into the image. Pass secrets at run time with docker run --env-file .env or your orchestrator's secret store.Logs
Your bot writes to logs/bot.log and to stdout. Mount or ship LOG_DIR somewhere persistent if you want logs to survive a container restart, and set LOG_LEVEL=INFO or higher in production.