A free bot host works until the container sleeps or the service shuts down mid-event. A $3 VPS with systemd keeps the bot online for real. This is the how-to; for the fuller walkthrough and music-bot notes, see host a Discord bot on a VPS and the VPS for Discord bots use-case. No dedicated IP needed — a Discord bot only makes outbound connections, so a NAT plan (from $3/mo) is ideal.
1. Install the runtime and your bot (Node example)
apt update && apt install -y curl git
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install -y nodejs
git clone https://github.com/you/your-bot.git /opt/bot
cd /opt/bot && npm ci --omit=dev
2. Keep the token in an env file
cat >/opt/bot/.env <<'EOF'
DISCORD_TOKEN=your_token_here
EOF
chmod 600 /opt/bot/.env
3. systemd service with Restart=always
# /etc/systemd/system/discordbot.service
[Unit]
Description=Discord Bot
After=network.target
[Service]
WorkingDirectory=/opt/bot
ExecStart=/usr/bin/node index.js
EnvironmentFile=/opt/bot/.env
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now discordbot
journalctl -u discordbot -f
Restart=always is what makes it 24/7 — an unhandled rejection at 3 a.m. restarts instead of leaving the bot dead. (More in create a systemd service.)
Python instead?
Same pattern — a venv and discord.py, with the unit pointing at the venv Python:
ExecStart=/opt/bot/.venv/bin/python bot.py
Notes
- Several bots? Copy the unit per bot (
discordbot-a.service, …), or run each in a container with Docker's--restart unless-stopped. - Music bot? Add
ffmpegand step up to Micro/Small — audio encoding is the one thing here that wants CPU. Traffic is unmetered on every plan, so streaming won't run up a bill.
Nano at $3/mo, root in about a minute, no KYC, pay in crypto — cheap enough to be disposable when a bot project ends. Same pattern for Telegram bots.
Comments
No comments yet. Be the first.