# How to Host a Discord Bot in 2026 and Keep It Online 24/7

> Want your Discord bot online 24/7 in 2026? No server setup, no cold starts, one-click deploy, zero downtime. A full guide for Python and Node.js bots.
- **Author**: parth-kanpariya
- **Published**: 2026-04-20
- **Modified**: 2026-06-25
- **Category**: Deployment Guides
- **URL**: https://kuberns.com/blogs/how-to-deploy-discord-bot/

---

Building a Discord bot is the easy part. Keeping it online is where most developers hit a wall.

You write the code, test it locally, the bot responds perfectly. Then you deploy to a free platform and find it goes offline after fifteen minutes. Or you try a VPS and spend two hours writing systemd service files, configuring a firewall, and setting up process managers for something that should just run.

Discord bots are persistent processes. They open a WebSocket connection to Discord's gateway and hold it open indefinitely, listening for events. That architecture rules out serverless platforms entirely and causes problems on any host with an inactivity timeout. The bot never receives inbound HTTP requests, so platforms that sleep idle services will shut it down almost immediately.

The right way to host a Discord bot in 2026 is a platform that keeps persistent background processes alive without a sleep timer. This guide covers the full setup: bot prerequisites, step-by-step deployment on Kuberns, how to handle common Discord-specific requirements, and the errors that cause bots to silently go offline.

**What this guide covers:**
- What your Discord bot needs before any deployment will work
- Step-by-step deployment on Kuberns (Python and Node.js)
- Why most free platforms fail for Discord bots
- Common errors and how to fix them
- FAQ: the most searched Discord bot hosting questions

## What Your Discord Bot Needs Before Deployment

Before any platform can run your Discord bot reliably, four things need to be correct. Miss any one of them and your bot either won't start or will go offline silently.

### 1. A bot token from the Discord Developer Portal

Every Discord bot authenticates with a token. If you haven't created one yet:

1. Go to [discord.com/developers/applications](https://discord.com/developers/applications)
2. Click **New Application**, give it a name
3. Go to the **Bot** tab and click **Add Bot**
4. Under the **Token** section, click **Reset Token** and copy it
5. Enable **Message Content Intent** under Privileged Gateway Intents if your bot reads message content

That token is the master key to your bot. Anyone who has it can control your bot completely. Never put it directly in your code and never commit it to GitHub. It belongs only in your deployment platform's environment variables dashboard, set as `DISCORD_BOT_TOKEN`.

If you accidentally expose your token in a commit, go back to the Developer Portal and regenerate it immediately.

### 2. requirements.txt (Python) or package.json (Node.js) with all dependencies

When you deploy, the platform installs your dependencies fresh on the server. If a library is missing from this file, the deployment looks successful but the bot crashes on startup.

**For Python bots using discord.py:**

```
discord.py==2.3.2
python-dotenv==1.0.0
```

Generate exact versions from your local environment:

```bash
pip freeze > requirements.txt
```

Review the output and keep only what your bot actually imports. `pip freeze` captures everything including dev tools you don't need on the server.

**For Node.js bots using discord.js:**

Your `package.json` should include:

```json
{
  "dependencies": {
    "discord.js": "^14.14.1",
    "dotenv": "^16.3.1"
  },
  "scripts": {
    "start": "node index.js"
  }
}
```

Run `npm install` locally first to generate a `package-lock.json`, then commit both files.

### 3. An entry file at the root of your repository

The platform needs one file to start your bot. For Python bots, name it `bot.py` or `main.py` and place it at the root of your project. For Node.js bots, use `index.js` at the root.

**Python (discord.py) - production-ready bot:**

```python
import discord
import os
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix="!", intents=intents)

@bot.event
async def on_ready():
    print(f"Bot is online: {bot.user}")

@bot.command()
async def ping(ctx):
    await ctx.send(f"Pong! Latency: {round(bot.latency * 1000)}ms")

bot.run(os.environ["DISCORD_BOT_TOKEN"])
```

**Node.js (discord.js) - production-ready bot:**

```javascript
const { Client, GatewayIntentBits } = require("discord.js");
require("dotenv").config();

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});

client.once("ready", () => {
  console.log(`Bot is online: ${client.user.tag}`);
});

client.on("messageCreate", (message) => {
  if (message.content === "!ping") {
    message.reply(`Pong! Latency: ${client.ws.ping}ms`);
  }
});

client.login(process.env.DISCORD_BOT_TOKEN);
```

### 4. Token read from an environment variable, never hardcoded

For local development, create a `.env` file at your project root:

```
DISCORD_BOT_TOKEN=your_token_here
```

Add `.env` to your `.gitignore` before your first commit:

```
.env
```

Confirm it's excluded before pushing. When you deploy, you'll set `DISCORD_BOT_TOKEN` directly in the Kuberns environment dashboard. The value is encrypted at rest and never appears in build logs.

> Building a bot that also runs a web dashboard alongside the Discord connection? See our guide on [deploying microservices without managing multiple tools](https://kuberns.com/blogs/how-to-deploy-microservices-without-managing-multiple-tools/) - the same multi-service approach works for a bot plus a web backend.

<a href="https://dashboard.kuberns.com" target="_blank" rel="noopener noreferrer">
  <img src="https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/deploy-on-kuberns-bannner6.png" alt="Deploy Discord Bot on Kuberns" style={{ width: "100%", height: "auto" }} />
</a>

## How to Deploy a Discord Bot on Kuberns (Step by Step)

[Kuberns](https://kuberns.com/) is an agentic AI deployment platform that keeps persistent background processes running 24/7 on AWS infrastructure. For Discord bots, the AI reads your `requirements.txt` or `package.json`, detects Python or Node.js, installs dependencies, starts your bot process, and keeps it alive permanently with no idle timeout, no sleep mode, and automatic restarts if it ever crashes.

### Step 1: Create Your Kuberns Account

Go to [kuberns.com](https://kuberns.com) and click **Deploy for Free**. Create your account and verify your phone number.

Kuberns has a free tier to start. After that, $7 gets you $14 in compute credits - 2x value to apply toward your deployment. [See pricing](https://kuberns.com/pricing/).

### Step 2: Connect Your GitHub Repository

On the **Creating a Service** page, connect your GitHub account and select your Discord bot repository.

- Click **Connect to GitHub** and authorise Kuberns access to your repositories
- Select your Discord bot repository and the branch you want to deploy (typically `main`)
- Kuberns reads your `requirements.txt` or `package.json`, detects the language, and configures the start command automatically - you confirm, not configure

### Step 3: Add Your Environment Variables

Before clicking Deploy, navigate to the Environment section:

- Click **Add Env Vars** and input key-value pairs manually, or
- Click **Upload .env file** to import all variables at once

Add at minimum:

| Variable | Value |
|---|---|
| `DISCORD_BOT_TOKEN` | Your bot token from the Developer Portal |
| `DISCORD_GUILD_ID` | Your server ID (if using guild-specific slash commands) |

If your bot calls external APIs (OpenAI, a database, a weather service), add those keys here too. All values are encrypted at rest and never appear in build logs.

### Step 4: Click Deploy - The AI Takes Over

Click **Deploy**. The Kuberns agentic AI takes over from here:

- Installs all packages from `requirements.txt` (Python) or `package.json` (Node.js)
- Starts your bot: `python bot.py` or `node index.js`
- Keeps the process running permanently with no inactivity shutdown
- Restarts the bot automatically if it ever crashes
- Redeploys on every GitHub push - push new code and your bot updates in seconds with zero downtime
- Provides real-time logs so you can see exactly what your bot is doing

### Step 5: Invite Your Bot and Test It

Go to your Discord server. Type `!ping` (or your bot's command). It replies instantly.

Your bot is live 24/7 on AWS infrastructure.

From the Kuberns dashboard you can:
- View live logs and crash reports
- Update environment variables without redeploying
- Check resource usage and uptime
- Monitor CI/CD deploy history

[Deploy your Discord bot on Kuberns](https://dashboard.kuberns.com)

## Why Most Free Platforms Fail for Discord Bots

This is the most common frustration Discord bot developers run into. Understanding why it happens helps you choose the right host.

### The core problem: Discord bots are persistent processes

A Discord bot opens a WebSocket connection to Discord's gateway and holds it open indefinitely. It never receives inbound HTTP requests. It just sits there, connected, waiting for events.

Platforms that sleep idle services look for inbound HTTP traffic. No traffic = no activity = service sleeps. A Discord bot will always trigger this shutdown because it has no inbound HTTP traffic by design.

**What happens on each platform:**

| Platform | What Happens | Suitable for Discord Bots |
|---|---|---|
| **Kuberns** | Persistent process, no sleep, auto-restart | Yes |
| Render (free tier) | Sleeps after 15 min of no HTTP traffic | No |
| Railway (free tier) | $5 trial credit, then paid only | Limited |
| Vercel | Serverless, no persistent connections | No |
| AWS Lambda | Function-based, terminates after execution | No |
| Heroku (free tier) | Removed in 2022 | Gone |
| Replit | Free tier sleeps, paid tier works | Paid only |
| VPS (DigitalOcean, Hetzner) | Works but requires manual setup | Yes, with setup |

### Why serverless doesn't work for Discord bots

Serverless platforms like Vercel, AWS Lambda, and Cloudflare Workers are designed for functions that run briefly and terminate. A Discord bot needs to maintain a persistent WebSocket connection. These two architectures are incompatible. You physically cannot run a Discord bot on serverless infrastructure - it's not a configuration issue, it's architectural.

For a full comparison of platforms and what they're actually suited for, see our guide on [Heroku alternatives](https://kuberns.com/blogs/heroku-alternatives/) which covers how persistent process support varies across platforms.

## Handling Discord-Specific Production Requirements

### Slash Commands

Modern Discord bots use slash commands (`/command`) instead of prefix commands (`!command`). Slash commands need to be registered with Discord's API before they're visible in servers.

**Register commands globally (takes up to 1 hour to propagate):**

```python
@bot.event
async def on_ready():
    await bot.tree.sync()
    print(f"Synced slash commands. Bot online: {bot.user}")
```

**Register commands to a specific guild instantly (instant, for testing):**

```python
MY_GUILD = discord.Object(id=int(os.environ["DISCORD_GUILD_ID"]))

@bot.event
async def on_ready():
    bot.tree.copy_global_to(guild=MY_GUILD)
    await bot.tree.sync(guild=MY_GUILD)
    print(f"Synced commands to guild. Bot online: {bot.user}")
```

Add `DISCORD_GUILD_ID` as an environment variable in Kuberns for guild-specific registration.

### Privileged Gateway Intents

Since Discord API v10, some intents require explicit enabling in the Developer Portal:

- **Server Members Intent** - needed if your bot lists or monitors server members
- **Message Content Intent** - needed if your bot reads the content of messages (not just reactions or mentions)
- **Presence Intent** - needed if your bot tracks online/offline status

Go to the Discord Developer Portal, open your application, go to the **Bot** tab, and enable the intents your bot uses. Then enable the same intents in your code:

```python
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
```

If you see a `PrivilegedIntentsRequired` error in your Kuberns logs, this is the fix.

### Background Tasks

If your bot runs scheduled tasks (posting daily updates, checking an API every hour, sending reminders), use discord.py's built-in task loop:

```python
from discord.ext import tasks

@tasks.loop(hours=1)
async def hourly_update():
    channel = bot.get_channel(int(os.environ["CHANNEL_ID"]))
    await channel.send("Hourly update from the bot")

@bot.event
async def on_ready():
    hourly_update.start()
```

This runs inside the bot's existing process on Kuberns. No separate worker or cron job needed.

### Connecting to a Database

If your bot stores data (user preferences, server settings, leaderboards), connect to an external database via environment variables. Add the connection string to Kuberns:

```
DATABASE_URL=postgresql://user:password@host:5432/dbname
```

Free PostgreSQL options: [Neon](https://neon.tech), [Supabase](https://supabase.com). Both give you a `DATABASE_URL` connection string you paste directly into Kuberns environment variables.

For bots that also expose a web dashboard or API alongside the Discord connection, see our guide on [deploying a full-stack app with AI](https://kuberns.com/blogs/how-to-deploy-a-full-stack-app-with-ai-complete-step-by-step-guide/).

## Common Discord Bot Deployment Errors and Fixes

**`discord.errors.LoginFailure: Improper token has been passed`**
Your `DISCORD_BOT_TOKEN` environment variable is missing, wrong, or the token was reset in the Developer Portal after you copied it. Check the Kuberns environment dashboard and regenerate the token if needed.

**`discord.errors.PrivilegedIntentsRequired`**
You're using an intent (message content, server members, presence) that isn't enabled in the Discord Developer Portal. Enable the required intents under the Bot tab in your application settings.

**`ModuleNotFoundError: No module named 'discord'`**
`discord.py` is not in your `requirements.txt`. Add `discord.py==2.3.2` and redeploy.

**Bot comes online but slash commands don't appear in Discord**
Slash commands need to be synced to Discord after the bot starts. Check your `on_ready` event includes `await bot.tree.sync()`. Global commands can take up to one hour to propagate - use guild-specific sync for instant testing.

**Bot goes offline after a few minutes**
This happens when deployed on platforms with inactivity timeouts (Render free tier). Kuberns does not have this issue - your bot runs as a persistent process with no sleep timer.

**`heartbeat blocked for more than 10 seconds`**
Your bot is doing blocking synchronous work inside async event handlers. Use `asyncio` for any I/O operations (database queries, API calls) inside event handlers instead of synchronous libraries.

## Deployment Checklist for Your Discord Bot

Before you share your bot invite link publicly, run through this:

- Bot token from Discord Developer Portal, set as `DISCORD_BOT_TOKEN` environment variable only, never in code
- `requirements.txt` complete with `discord.py` version pinned (Python), or `package.json` with `discord.js` listed (Node.js)
- `bot.py` or `index.js` at repository root, reads token with `os.environ["DISCORD_BOT_TOKEN"]`
- `.env` in `.gitignore`, confirmed not committed to repository
- Required Privileged Gateway Intents enabled in Developer Portal and in code
- GitHub repository connected to Kuberns
- `DISCORD_BOT_TOKEN` set in Kuberns environment dashboard
- Build logs show no errors, runtime logs show bot coming online
- `!ping` or your test command works in Discord
- Slash commands synced via `bot.tree.sync()` in `on_ready`
- Auto-redeploy confirmed: push a small commit, verify the bot updates without manual steps

## Your Bot Is Ready. Deploy It Now.

You've written the code. You have the token. The hard part is done.

Everything between your Python or Node.js script and a bot running 24/7 on production infrastructure is five steps on Kuberns: connect your GitHub repository, add `DISCORD_BOT_TOKEN` as an environment variable, click Deploy, watch the logs, and send a test command in Discord.

No server to provision. No systemd service files. No Nginx config. No sleep timer counting down in the background. No Docker.

Your bot runs on AWS infrastructure with automatic restarts, CI/CD on every GitHub push, and real-time logs. The free tier gets you started today. When you need more, $7 gets you $14 in compute credits.

Push your code to GitHub and ship it.

[Deploy your Discord bot on Kuberns](https://dashboard.kuberns.com)

<a href="https://dashboard.kuberns.com" target="_blank" rel="noopener noreferrer">
  <img src="https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/CTA_banner.png" alt="Deploy on Kuberns" style={{ width: "100%", height: "auto" }} />
</a>

## Frequently Asked Questions

Connect your GitHub repository to Kuberns, add `DISCORD_BOT_TOKEN` as an environment variable, and click Deploy. Kuberns keeps your bot running 24/7 on AWS infrastructure with no sleep mode, no cold starts, and automatic restarts if the process crashes. [Start for free](https://dashboard.kuberns.com).

### What is the best free hosting for a Discord bot in 2026?

Kuberns is the best option for running a Discord bot 24/7 in 2026. Unlike Render's free tier which sleeps services after 15 minutes of no HTTP traffic, Kuberns keeps persistent processes alive continuously. Vercel and AWS Lambda cannot run Discord bots at all - bots require persistent WebSocket connections that serverless platforms don't support.

### Why does my Discord bot go offline after a few minutes?

This is almost always an inactivity timeout on your hosting platform. Discord bots hold a WebSocket connection open but never receive inbound HTTP requests. Platforms that sleep "idle" services see no inbound traffic and shut the bot down. Render's free tier is the most common cause. Kuberns does not have this problem - it keeps persistent background processes running indefinitely.

### Do I need a server to host a Discord bot?

No. With Kuberns, you connect your GitHub repo, add your bot token as an environment variable, and click Deploy. Kuberns provides the server, manages the process, handles restarts, and enables CI/CD. No SSH access, no VPS setup, no systemd service files.

### Can I deploy a Discord.js (Node.js) bot on Kuberns?

Yes. Kuberns supports both Python (discord.py) and Node.js (discord.js) bots. For Node.js bots, push your `package.json` and `index.js` to GitHub, connect the repository, add `DISCORD_BOT_TOKEN`, and deploy. Kuberns detects Node.js automatically from your project files.

### Can I deploy a Discord bot without Docker?

Yes. Kuberns does not require a Dockerfile. Push your bot code and `requirements.txt` (Python) or `package.json` (Node.js) to GitHub, connect the repository, add your bot token, and deploy. Kuberns detects the language automatically and handles everything else.

### How long does it take to deploy a Discord bot on Kuberns?

Most Discord bots are live within 3 to 5 minutes of clicking Deploy on Kuberns, including dependency installation and process startup.

### Can my Discord bot also run a web server?

Yes. If your bot exposes a web dashboard or API alongside the Discord connection, you can run both in the same service or use Kuberns' multi-service support to deploy them separately. See our guide on [deploying microservices without managing multiple tools](https://kuberns.com/blogs/how-to-deploy-microservices-without-managing-multiple-tools/).

---
- [More Deployment Guides articles](https://kuberns.com/blogs/category/deployment-guides/1/)
- [All articles](https://kuberns.com/blogs/)