EN · $ USD
Discord Bot Hosting

Discord Bot Keeps Going Offline: How to Fix It

7 min read Updated: OyunBulut technical team

In short

If your Discord bot keeps going offline, the cause is usually an uncaught error crashing the process, no process manager like PM2 or systemd to restart it, the server running out of memory, a rate limit or IP restriction from invalid requests, or a privileged intent that isn't enabled in the Developer Portal. Check the output of pm2 logs, journalctl, and dmesg first to pin down the cause, then apply the matching fix.

In this guide
  1. Diagnose first: don't guess without checking the logs
  2. 1. Uncaught errors are crashing the process
  3. 2. There's no process manager
  4. 3. Not enough memory
  5. 4. Rate limits and temporary IP restrictions
  6. 5. Missing intents
  7. Other checks
  8. Know your bot is down before your users do
  9. Next step: move your bot to an environment that stays connected

If your Discord bot keeps going offline, the cause is almost always one of five things: an uncaught error is crashing the process, there's no process manager to restart the bot, the server is running out of memory, the bot is hitting a rate limit or a temporary IP restriction, or the connection is rejected because an intent isn't enabled in the Developer Portal. Below, we show how to recognize each one from your log output and how to fix it for good.

Diagnose first: don't guess without checking the logs

"The bot went down" is a symptom, not a cause. Your first job is to see what the bot printed right before it went down. Depending on how you run your bot, read the logs with these commands:

# If it runs under PM2
pm2 logs bot-adi --lines 200

# If it's a systemd service
sudo journalctl -u bot-adi -n 200 --no-pager

# Did the kernel kill the process because of memory?
dmesg -T | grep -i -E "killed process|out of memory"

Match what you see in the logs to a cause using the table below:

Symptom in the logsLikely causeSection
UnhandledPromiseRejection, TypeError, then the process exitsUncaught error1
Logs stop abruptly; the bot drops when the terminal or PC shuts downNo process manager2
Killed, JavaScript heap out of memory, Out of memory in dmesgNot enough memory3
429 Too Many Requests, a Cloudflare error page, 1015Rate limit / IP restriction4
Used disallowed intents or close code 4014Missing intent5
An invalid token was provided or code 4004Token reset or incorrectOther checks

1. Uncaught errors are crashing the process

This is the most common cause. In current versions of Node.js, an uncaught Promise rejection (unhandled rejection) ends the process by default. Trying to reply to a deleted message, posting in a channel the bot has no permission for, or an API returning nothing can take the bot down on its own.

The fix has two layers. First, wrap your command handlers in try/catch. Second, add a safety net that logs any errors that slip through:

// discord.js
client.on('error', (err) => console.error('İstemci hatası:', err));
client.on('shardError', (err) => console.error('Shard bağlantı hatası:', err));

process.on('unhandledRejection', (reason) => {
  console.error('Yakalanmamış Promise reddi:', reason);
});

client.on('interactionCreate', async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  try {
    await komutuCalistir(interaction);
  } catch (err) {
    console.error(`/${interaction.commandName} hatası:`, err);
    if (!interaction.replied) {
      await interaction.reply({ content: 'Bir hata oluştu.', ephemeral: true }).catch(() => {});
    }
  }
});

If you use discord.py, you get the same effect by defining the on_error event and, for commands, on_command_error / tree.on_error. This safety net isn't there to hide errors but to make them visible: read the errors that pile up in your logs regularly and fix them at the source.

2. There's no process manager

If you started your bot in an SSH session with node index.js or python bot.py, the bot stops when the session closes. It also won't come back on its own when the server reboots. Every bot should run under a process manager, a tool that automatically restarts your app when it crashes and starts it when the server boots.

npm install -g pm2
pm2 start index.js --name bot-adi --max-restarts 20 --restart-delay 5000
pm2 save
pm2 startup   # copy and run the command it prints

For Python bots, a systemd service is the more natural choice; you'll find the full setup in our guide to running a discord.py bot with systemd. For Node.js bots, PM2 is the most popular choice.

Note: a process manager hides crashes, it doesn't fix them. If the restart count in pm2 list keeps climbing, you need to fix the errors from section 1.

3. Not enough memory

If your bot runs fine for a few hours or days and then shuts down with no explanation, suspect a memory leak. When a Linux system runs out of memory, the OOM Killer kills the process using the most memory; the log usually just says Killed.

What to check:

  • Cache growth: discord.js keeps messages and members in memory. On large servers, that cache takes up a lot of space. Limit it with the makeCache and sweepers options.
  • Arrays and Maps that grow forever: Code that keeps piling up cooldown, XP, or session data without ever clearing it.
  • Other apps on the same server: A database, Lavalink, or a second bot can use up the total memory.
// Limit the message cache and sweep old messages
const { Client, GatewayIntentBits, Options } = require('discord.js');
const client = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
  makeCache: Options.cacheWithLimits({ MessageManager: 50 }),
  sweepers: { messages: { interval: 3600, lifetime: 1800 } }
});

With PM2, you can also add a controlled restart when the process crosses a set limit using --max-memory-restart 400M. That's a temporary patch; the real fix is either finding the leak or giving the bot the RAM it needs. If your bot has grown and your measurements show a legitimate increase, the OB-DISCORD-2 plan with 4 vCPU and 3 GB RAM relieves the memory pressure you get on smaller plans.

4. Rate limits and temporary IP restrictions

A rate limit is a cap on how many requests the Discord API accepts in a given time window. Libraries handle normal rate limits on their own by waiting. The problem is when the bot sends lots of invalid requests: requests that keep returning 401, 403, or 429. Discord temporarily restricts IP addresses that make too many invalid requests in a short time. When that happens, the bot can't reconnect, and you'll see a Cloudflare error page in the logs.

Typical causes:

  • The bot stuck in a loop trying to reconnect with the wrong token.
  • Trying to send a message to a channel it has no permission for on every event (constant 403s).
  • Running bulk actions like role assignment or DMs in a loop without waiting.
  • Bad behavior from other bots sharing the same IP on free shared platforms.

That last one is a common reason for random disconnects on free hosting. A server with its own IP address removes this risk. For a detailed comparison, see our article are free Discord bot hosting sites good enough?

5. Missing intents

An intent is a permission that specifies which types of events your bot wants to receive from Discord. Message Content, Server Members, and Presence are "privileged" intents: besides requesting them in code, you have to turn them on separately in the Bot tab of the Developer Portal. If you request them in code but don't enable them in the portal, Discord closes the connection with code 4014 Disallowed intent(s) and the bot never comes online.

The fix: turn on the relevant toggles in the Developer Portal, or remove the intents you don't actually use from your code. Once your bot reaches 100 or more servers, you need to go through Discord's approval process for privileged intents; unapproved intents can cause problems at that point.

Other checks

  • Invalid token (4004): The token may have been reset. Discord invalidates tokens it finds in public repositories. We cover the causes and prevention in our token security guide.
  • Sharding required (4011): Once your bot passes a certain number of servers, a single connection isn't enough; use ShardingManager in discord.js.
  • Computer or network outages: If the bot runs on a home PC, sleep mode, a Windows update, or a router reboot will also take it down.
  • Library version: Very old discord.js/discord.py versions may fail to connect after Discord API changes. Keep your dependencies up to date.

Know your bot is down before your users do

Once you've fixed the problem, you'll want to know right away if it comes back. You don't need a complex monitoring system for that:

  1. Startup notification: Have the bot send a "bot started" message to a private channel or a Discord webhook on the ready event. If you see that message more than once a day, the bot is restarting.
  2. Restart counter: Once a week, check the restart column in pm2 list or the start time in systemctl status bot-adi.
  3. Log rotation: PM2 logs can fill your disk over time. Cap log file size with pm2 install pm2-logrotate; a full disk can also crash your bot.
  4. Resource monitoring: Use pm2 monit or htop to see whether your bot's memory usage keeps rising over time. Steady growth is the clearest sign of a leak.

Next step: move your bot to an environment that stays connected

Once the code-side bugs are fixed, what's left is the environment: running the bot on a server that stays on around the clock, has its own IP, and has enough memory. OyunBulut's Discord Bot VDS plans in Istanbul come with KVM virtualization, root access, and multi-layer DDoS protection; you install and manage PM2 or systemd yourself. For bots that crash from memory pressure or are growing, running your bot 24/7 on OB-DISCORD-2 is a sensible starting point. If you get stuck, you can open a support ticket for help.

Frequently asked questions

Why does my Discord bot shut down after a few hours?

Usually because of a memory leak or the OOM Killer. Look for an 'Out of memory' line in the dmesg output, limit the discord.js cache, and check your server's RAM.

Why does my bot go offline when I close SSH?

The bot is tied to your terminal session. If you start it with a process manager like PM2 or systemd, it keeps running when you close the session and after the server reboots.

How do I fix the 'Used disallowed intents' error?

Turn on the Message Content, Server Members, or Presence intent you request in code from the Bot tab in the Developer Portal, or remove it from your code if you don't use it.

Can rate limits take my Discord bot offline?

Your library handles normal rate limits. However, IP addresses that send too many invalid requests in a short time can be temporarily restricted, and the bot can't connect during that time.

Why does my bot drop so often on free hosting?

Free platforms share resources and IP addresses and may put apps to sleep. Bad behavior from other bots can get the shared IP restricted; your own server removes that risk.

My PM2 restart count keeps going up. What should I do?

It means the bot is crashing and restarting. Use pm2 logs to find the error right before the crash, wrap that code in try/catch, and fix the error at the source.

For this guide

Recommended plans

OB-DISCORD-2 and our Discord Bot VDS plans give your bot its own IP, enough RAM, and root access, eliminating the disconnects caused by sleeping apps, IP restrictions, and memory pressure on shared platforms.

OB-DISCORD-2

Recommended

3 GB RAM

$2.26/mo

+VAT

  • Processor4 vCPU
  • ModelAMD Ryzen / Intel
  • Disk35 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

2 GB RAM

$1.96/mo

+VAT

  • Processor2 vCPU
  • ModelAMD Ryzen / Intel
  • Disk30 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

4 GB RAM

$2.55/mo

+VAT

  • Processor4 vCPU
  • ModelAMD Ryzen / Intel
  • Disk40 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

Discord Bot VDS — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.