Skip to content

Discord bots

How to keep your Discord bot online 24/7

Why bots go offline, and the setup that keeps yours running around the clock without you watching it.

Every bot developer has been there: the bot works perfectly while you're testing, then goes offline the moment you close your laptop, or dies at 3am and stays down until someone complains. Keeping a Discord bot online 24/7 isn't one setting. It's a few simple habits that together make downtime rare and short.

Why Discord bots go offline

A bot is just a program that keeps a WebSocket connection open to Discord's gateway. It shows as online only while that program is running and connected. It goes offline when:

  • The computer it runs on stops. Your PC sleeps, restarts for updates or loses its internet connection.
  • The process crashes. An unhandled error or promise rejection kills the program, and nothing starts it again.
  • The host puts it to sleep. Many free platforms suspend apps that don't receive web traffic, or limit how many hours you can run each month.
  • It runs out of memory. Caches grow until the system kills the process.
  • The token changes. If your token leaks, Discord resets it, and the bot can't log in until you update it.
  • It gets rate limited. On shared IP addresses, other people's bots can use up the limits, and Discord temporarily blocks the whole IP.

Step 1: run it on a server, not your PC

The first fix is the biggest: move the bot onto a machine that's built to stay on. That can be a bot hosting plan, where you upload your code and press start, or a VPS, where you manage a Linux server yourself. Either way, the server runs in a datacenter with redundant power and network, so the bot no longer depends on your home connection.

If you only need to run the bot, managed bot hosting is the easiest route. If you also need a dashboard, open ports or Docker, see bot hosting vs VPS.

Step 2: restart automatically after crashes

Bugs happen. What matters is that a crash costs seconds, not hours. On Zettako's bot hosting, the panel detects a crashed server and starts it again for you. On a VPS, use a process manager:

  • systemd, built into most Linux distributions. Set Restart=always in the service file.
  • PM2 for Node.js bots: pm2 start index.js --name my-bot, then pm2 save and pm2 startup so it survives reboots.
  • Docker with restart: unless-stopped in your compose file.

A minimal systemd service looks like this:

[Unit]
Description=My Discord bot
After=network-online.target

[Service]
User=bot
WorkingDirectory=/home/bot/my-bot
EnvironmentFile=/home/bot/my-bot/.env
ExecStart=/usr/bin/node index.js
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Step 3: stop small errors from becoming crashes

Automatic restarts are a safety net, not a strategy. Most crashes come from a single unhandled error in one command. Catch errors in your command handlers and log them instead of letting them kill the process. In discord.js, also listen for client errors and unhandled rejections:

client.on(Events.Error, (error) => console.error('Client error:', error));
process.on('unhandledRejection', (error) => console.error('Unhandled rejection:', error));

In discord.py, override on_command_error (or the app command tree's on_error) so one bad command reports a friendly message instead of taking everything down.

Step 4: keep memory under control

A bot that slowly uses more memory will eventually be killed and restarted, often in the middle of something important. Only request the gateway intents you need, limit caches, and watch the memory graph in your panel over a few days. If usage climbs and never drops, you have a leak to fix. If it levels off, you know the plan size you need. Our guide to how much RAM a Discord bot needs goes into the details.

Step 5: know when it goes down

Uptime monitors that ping a website can't see a bot, because bots don't serve web pages. Instead:

  • Have the bot post to a private log channel or webhook when it starts, so unexpected restarts are visible.
  • Use a heartbeat monitor: the bot sends a request to the monitor every minute, and you get an alert when the requests stop.
  • Check your host's status page. Ours is at status.zettako.net.

Step 6: protect your token

A leaked token takes your bot offline as surely as a crash: Discord resets tokens it finds in public repositories. Keep the token in an environment variable or .env file, add .env to .gitignore, and never paste it into support chats or screenshots.

Avoid the "keep-alive" trick

Old tutorials suggest running a tiny web server inside your bot and pinging it every few minutes so a free host never puts it to sleep. It often breaks the host's terms, it stops working whenever the platform changes its rules, and you still share IP addresses with thousands of other bots. If the bot matters to your community, a small paid server is cheaper than the time you'll spend fighting it. We compare the options in free vs cheap Discord bot hosting.

The short version

  1. Run the bot on a server, not your PC.
  2. Restart it automatically when it crashes.
  3. Catch errors so it crashes less.
  4. Keep memory in check.
  5. Get alerted when it goes down.
  6. Keep the token secret.

Host your bot 24/7

Upload your code, press start, and let the panel restart your bot if it ever crashes.

Starting at $2.67USD/mo