Your bot answers commands while node index.js or python main.py runs on your computer. Close the laptop and, shortly after, it shows as offline. Nothing is broken: a bot only exists while its process runs, so hosting it 24/7 means running that process on a machine that never sleeps.
This guide explains why, compares the four ways to do it, and walks through two setups end to end: a managed host (ours, Bot-Hosting) and a plain VPS with pm2 or systemd, for those who would rather run their own server. Every claim about another provider comes from its own website, checked on 30 November 2026, with the links at the end.
Why your bot goes offline when you close your PC
A website waits for visitors. A Discord bot never gets one. When it starts, it dials out to Discord’s gateway and opens one WebSocket connection. Over that connection, the bot sends regular heartbeats and Discord pushes events: messages, slash commands, members joining. As long as the connection is open and the heartbeats arrive, Discord shows the bot as online.
Three consequences follow, and they decide which hosting works:
- The process must run all the time. When your PC sleeps, the process freezes, the heartbeats stop and Discord drops the session.
- “Free hosting” built for websites puts bots to sleep. Many free tiers stop an app after some minutes without inbound HTTP requests. A bot receives none, so it looks idle forever.
- Something must restart the bot. A crash, a reboot or a network hiccup that kills the process should not need you.
On top of that, the bot needs its token stored outside the code, and its files kept between restarts if it saves anything to disk.
The four ways to keep a Discord bot online 24/7
1. Your own PC or a Raspberry Pi
It works, it costs nothing upfront, and you learn a lot. A Raspberry Pi drawing a few watts is a classic home server for a small bot.
The limits are physical: the bot is offline whenever the power, the router or your ISP is. Your home connection carries the traffic, and a restart after a power cut is your job unless you set up pm2 or systemd, exactly as on a VPS (see below). Good for learning and for a bot only your friends use.
2. Free cloud tiers
Here is what the big general-purpose platforms offer for a bot today:
- Render: free instances exist for web services, not for background workers, the service type made for a bot. A free web service spins down after 15 minutes without inbound traffic, has no persistent disk, and Render may restart it at any time. The cheapest background worker costs $7 a month for 512 MB of RAM.
- Railway: the Free plan costs nothing, needs no card and includes $1 of usage a month. Its services sleep after 5 to 10 minutes without outbound traffic, and Railway says plainly that a bot holding a WebSocket keeps itself awake. The catch is the credit: at $10 per GB of RAM per month, $1 pays for about 100 MB of RAM around the clock, before any CPU. Hobby costs $5 a month including $5 of usage.
- Replit: since November 2026, the free Starter plan is no longer available to new users; new accounts get a 3-day trial of Core. Its default deployment type idles after 15 minutes, and the always-on type, a Reserved VM, starts at $15 a month for 0.5 vCPU and 2 GB of RAM. The Replit alternative guide covers moving a bot off it.
- Oracle Cloud Always Free: a real virtual machine, up to the equivalent of 2 Ampere OCPUs and 12 GB of RAM, but sign-up usually needs a card, the VM must live in your home region, and Oracle may reclaim instances it considers idle. A small bot can match that definition. You also run and secure Linux yourself, which is option 3 without the bill.
The Railway vs Render comparison does the arithmetic for a typical bot, and the free hosting comparison covers the bot-specific free hosts with the same criteria.
3. A VPS with pm2 or systemd
A small Linux server from any provider, a few euros or dollars a month, running your bot under a process manager. You get full control, room for several bots and a database, and nothing sleeps.
In exchange you are the administrator: updates, SSH keys, firewall, backups and monitoring. Done well, it is a great option. Left alone, a VPS with password login and no updates becomes someone else’s server. The setup is in its own section below.
4. A managed bot host
A host built for long-running processes: you upload the code or connect a GitHub repository, set the token, and the platform runs the process, restarts it and keeps the logs. That is what Bot-Hosting does. The trade-off is less control than a VPS: one container with fixed limits per bot, no root access to the machine.
Which option fits you
| Own PC or Pi | Free cloud tier | VPS | Managed bot host | |
|---|---|---|---|---|
| Cost | Electricity | $0, with limits | A few euros or dollars a month | Free plan or fixed monthly price |
| Online when you are away | Only if the machine and the connection are | Depends on the tier’s sleep and credit rules | Yes | Yes |
| Restarts after a crash | If you set up pm2 or systemd | Platform dependent | If you set up pm2 or systemd | Yes |
| Linux skills needed | Some | Few | Yes | No |
| Best for | Learning, a bot for friends | Testing, a bot that is part of a web project | Several bots, full control | One or more bots without server work |
If you want a short rule: learn on your PC, run in production on a VPS if you enjoy administering servers, and on a managed host if you would rather spend that time on the bot.
Host your bot on Bot-Hosting, step by step
The Free plan gives you 256 MB of RAM, 25% of a CPU core, 512 MB of storage and one deployment, without a card. It never sleeps. The one condition is a renewal click every 4 days, covered below.
Step 1: get the token and invite the bot
In the Discord Developer Portal, create an application, open Bot, click Reset Token and copy it: Discord shows it once. Then in OAuth2, tick the bot scope, which now includes applications.commands, choose the permissions, and open the generated URL to add the bot to your server.
Anyone with the token controls your bot. It goes in an environment variable, never in the code or a public repository.
Step 2: make the code host-ready
The code below is a complete bot with a /ping command. We ran it on 30 November 2026 with discord.js 14.28.1 on Node.js 22, up to Discord’s answer to a fake token, which is the furthest a test without a real token can go.
package.json:
{
"name": "my-bot",
"version": "1.0.0",
"private": true,
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "14.28.1"
}
} index.js:
const { Client, Events, GatewayIntentBits } = require('discord.js');
const token = process.env.DISCORD_TOKEN;
if (!token) {
console.error('DISCORD_TOKEN is not set');
process.exit(1);
}
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, async (c) => {
await c.application.commands.set([
{ name: 'ping', description: 'Replies with the bot latency' },
]);
console.log(`Logged in as ${c.user.tag}`);
});
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply(`Pong! ${client.ws.ping} ms`);
}
});
// Log errors instead of crashing on the first failed API call.
client.on(Events.Error, (err) => console.error('Client error:', err));
process.on('unhandledRejection', (err) => console.error('Unhandled rejection:', err));
// Close the gateway connection cleanly when the host stops the bot.
process.on('SIGTERM', async () => {
await client.destroy();
process.exit(0);
});
// A bad token is fatal: exit so the logs show it, instead of hanging.
client.login(token).catch((err) => {
console.error('Login failed:', err.message);
process.exit(1);
}); The same bot in Python, tested with discord.py 2.7.1 on Python 3.13. requirements.txt:
discord.py==2.7.1 main.py:
import os
import sys
import discord
from discord import app_commands
TOKEN = os.environ.get("DISCORD_TOKEN")
if not TOKEN:
sys.exit("DISCORD_TOKEN is not set")
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
@tree.command(description="Replies with the bot latency")
async def ping(interaction: discord.Interaction):
await interaction.response.send_message(f"Pong! {round(client.latency * 1000)} ms")
@client.event
async def setup_hook():
await tree.sync()
@client.event
async def on_ready():
print(f"Logged in as {client.user}", flush=True)
client.run(TOKEN) What makes this code ready for a server:
- The token comes from the environment and the bot refuses to start without it, with a clear message.
- Only the
Guildsintent (Intents.default()in Python, which leaves out the privileged ones). Slash commands need nothing more. Asking for privileged intents you have not enabled is a classic crash, explained in the disallowed intents fix. - Errors are logged, not swallowed. A failed login exits with the reason, so the console shows it.
Add a .gitignore with node_modules, .env and .venv. For the full walkthrough of each library, see the discord.js guide and the discord.py guide.
Step 3: create the deployment
Sign in on Bot-Hosting with Discord, then click New deployment:
- Type: choose Application.
- Source: GitHub to deploy a repository, or Archive to upload a
.zipof your folder withoutnode_modules. - Runtime: Node.js (version 24 by default) or Python (3.14 by default).
- Configure: name it and click Launch deployment. The entry file defaults to
index.jsfor Node.js andmain.pyfor Python; change it later in Startup if yours differs.
On every start, the deployment runs npm install when it finds a package.json, or pip install -r requirements.txt for Python, then starts your entry file. You never upload dependencies yourself. The GitHub guide shows how to pull the latest commit on each restart.
Step 4: add the token as a secret
Open the deployment’s Environment tab, click Add variable, set the key to DISCORD_TOKEN, paste the token and choose Secret. Secret values are hidden in the dashboard and in the logs. Saving restarts the deployment so the bot reads the new value.
Step 5: check the console
Open Console. You see the package install, then the line your code prints once Discord accepts the token:
Logged in as MyBot#1234 Type /ping in your server. If the bot does not start, the console shows why, and for the common failures (a refused token, missing intents, a missing module, running out of memory) it names the cause above the logs. The offline bot guide goes through each one.
Keep the free plan running
Renew the Free plan from the dashboard every 4 days, with one click. If you miss it, your deployment is suspended, and deleted if you do not renew within the next 3 days. The renewal guide shows where the button is. The free dashboard also shows ads; paid plans do not.
Paid plans renew on their own. Starter costs $2.29 a month for 1 GB of RAM, 50% of a core, 5 GB of storage and two deployments, enough for a bot and its database. The Discord bot hosting page lists what is included and the pricing page shows every plan in your currency.
Host it on a VPS instead
If you would rather run your own server, here is the minimum that keeps a Node.js bot online through crashes and reboots. Pick one of the two methods. Create a user for the bot instead of running it as root, and put the token in a .env file only that user can read:
DISCORD_TOKEN=your-token-here chmod 600 .env With pm2
pm2 is a process manager for Node.js. Install it (we tested 7.1.2), and add an ecosystem.config.js next to index.js:
module.exports = {
apps: [
{
name: 'my-bot',
script: 'index.js',
node_args: '--env-file=.env',
exp_backoff_restart_delay: 1000,
max_memory_restart: '400M',
},
],
}; npm install -g [email protected]
pm2 start ecosystem.config.js
pm2 logs my-bot
pm2 startup
pm2 save --env-file=.envlets Node.js (20.6 and later) load the token itself, so it stays out of the config file.exp_backoff_restart_delayrestarts a crashed bot after 1 second, then waits 1.5 times longer at each new crash, up to 15 seconds. A bot that crashes in a loop does not hammer Discord’s login.max_memory_restartrestarts the bot if it grows past 400 MB. Set it below your server’s RAM.pm2 startupprints a command: copy it and run it once, with sudo, to start pm2 at boot. Thenpm2 saverecords the running bots so they come back after a reboot.
With systemd
No extra software: systemd is already on most Linux servers. Create /etc/systemd/system/my-bot.service:
[Unit]
Description=My Discord bot
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=bot
WorkingDirectory=/home/bot/my-bot
EnvironmentFile=/home/bot/my-bot/.env
ExecStart=/usr/bin/node index.js
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target sudo systemctl daemon-reload
sudo systemctl enable --now my-bot
journalctl -u my-bot -f Restart=on-failure brings the bot back 5 seconds after a crash, enable starts it at boot, and journalctl follows the logs. For the Python bot, create a virtual environment in the bot’s folder, install the requirements into it, and use ExecStart=/home/bot/my-bot/.venv/bin/python -u main.py. The -u flag makes the logs appear immediately instead of being buffered. LimitNOFILE raises the open files limit, which matters for Python bots that open many connections.
Checklist: will your bot stay online?
Go through this list before you call it done, whatever the host:
- Restart on crash and on reboot. The host does it, or pm2 or systemd does.
- No sleep timer. The platform does not stop processes without inbound traffic.
- Token in an environment variable, never committed. A token pushed to a public GitHub repository gets reset by Discord.
- Only the intents you use, and the privileged ones enabled in the portal first.
- Errors logged. Unhandled promise rejections crash Node.js by default; log them and fix the cause.
- Slow commands deferred. Discord waits 3 seconds for the first response to a slash command, then shows “The application did not respond”.
- Memory watched. Caches grow with the number of servers; know your bot’s usage before you pick a plan.
- Data that survives. A SQLite file or JSON file needs storage kept between restarts, and a backup.
- Logs you can read when you were not watching.
- Free plan conditions known. Renewal, credit or sleep rules, whichever your host has.
FAQ
Can I host a Discord bot for free, 24/7?
Yes, with conditions that differ by host: a renewal every few days, a monthly credit that runs out, or a limit on RAM. Bot-Hosting’s Free plan never sleeps and asks for a renewal click every 4 days. The free hosting comparison lists what each provider asks.
Do I need to keep my PC on?
Only if the bot runs on it. Once it runs on a VPS or a host, your PC can be off.
Does the old Replit and UptimeRobot trick still work?
No. That trick pinged a small web server so Replit would keep a free project awake. Replit no longer offers its free plan to new users, and a free published app already went down after 30 days. On a host without a sleep timer, there is nothing to ping.
How much RAM does a Discord bot need?
A bot with slash commands in a few dozen servers runs in well under 256 MB. Music bots, bots that cache every member of large servers, and bots running a browser need more. Read the memory figure in your current host’s metrics, or in pm2 monit, before you choose.
Can I host several bots?
On a VPS, as many as its RAM allows. On Bot-Hosting, the Free plan has one deployment, and paid plans share one pool of RAM across several deployments, from two on Starter.
Can I host a self-bot or a bot on my user account?
No. Automating a user account, a self-bot, breaks Discord’s terms of service and gets accounts banned. Use a bot account from the Developer Portal.
My bot is online but does not answer. Is it the host?
Usually not. Missing intents, commands that were never registered and slow replies cause most of these cases. The offline and not responding guide has a flowchart to find yours.
Sources
Checked on 30 November 2026:
- Discord: Gateway, OAuth2 scopes and receiving and responding to interactions.
- Render: free instances and pricing.
- Railway: pricing and Free plan and trial.
- Replit: Starter plan and deployment pricing.
- Oracle Cloud: Always Free resources and free tier overview.
- pm2: startup script and restart strategies.
Prices and limits change. If one of these figures is out of date, the provider’s own page is the reference.