Guides

How to Host a Discord Bot 24/7 (discord.js and discord.py)

SkailarHost Team
November 16, 2026
8 min read
How to Host a Discord Bot 24/7 (discord.js and discord.py)

A Discord bot is only useful while it's online. Run it on your own PC and it disappears every time the PC sleeps, restarts or loses its connection. Here's how to set a bot up properly, keep its token safe, and run it on a server that keeps it online around the clock, with examples for both discord.js and discord.py.

TL;DR

Create the bot in the Discord Developer Portal, copy its token and invite it with the OAuth2 URL generator. Read the token from an environment variable, never from your code. Upload your project to an always-on host, set the start file and the DISCORD_TOKEN variable, and let the host restart the bot if it crashes. A small bot runs fine on 1 GB of RAM.

Why bots go offline

Where it runsCostWhat happens
Your own PCFreeGoes offline when the PC sleeps, restarts or loses internet
Free hosting tiersFreeUsually sleep when idle, limit hours or restart without warning
Bot hostingA few dollars a monthAlways on, restarts after a crash, no PC needed

A bot is a program that has to keep running to stay connected to Discord. When the program stops, for any reason, the bot shows as offline and stops answering. So "24/7" really means two things: a machine that's always on, and something that starts the bot again when it crashes.

Step 1: Create the bot in the Developer Portal

  1. Open the Discord Developer Portal, choose New Application and give it a name.
  2. Open the Bot page and choose Reset Token to see your token. Copy it somewhere safe: Discord only shows it once.
  3. Still on the Bot page, turn on the Privileged Gateway Intents your bot needs. Message Content is only needed if the bot reads the text of messages (for example prefix commands like !help), and Server Members only if it tracks who joins or leaves.
  4. Open OAuth2, then the URL generator. Tick the bot and applications.commands scopes, pick the permissions the bot needs, then open the generated link and add the bot to your server.

Step 2: Keep your token secret

The token is the bot's password. Anyone who has it can log in as your bot and do anything it can do in every server it's in.

  • Never put it in your code. Read it from an environment variable instead, like DISCORD_TOKEN.
  • Never commit it to GitHub. If you use a .env file, add it to .gitignore. Discord resets tokens it finds in public repositories, which takes your bot offline.
  • Leaked it? Press Reset Token in the Developer Portal straight away. The old token stops working immediately.

Step 3: A minimal bot

discord.js (Node.js)

Save this as index.js, with a package.json that lists discord.js as a dependency. Use the Node.js version the discord.js docs ask for: it goes up over time, so check before you deploy.

const { Client, Events, GatewayIntentBits } = require("discord.js");

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

client.once(Events.ClientReady, (c) => {
  console.log("Logged in as " + c.user.tag);
});

client.login(process.env.DISCORD_TOKEN);

discord.py (Python)

Save this as main.py, with a requirements.txt containing discord.py.

import os
import discord

intents = discord.Intents.default()
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f"Logged in as {client.user}")

client.run(os.environ["DISCORD_TOKEN"])

Both only connect and log a line, which is all you need to test hosting. Build your commands on top once it works.

Step 4: Put it on a server that's always on

  1. Upload your project with the file manager or over SFTP. Leave out node_modules and virtual environments: the packages from package.json or requirements.txt get installed on the server.
  2. Set the start file (index.js or main.py) in the panel's startup settings.
  3. Add your token as the DISCORD_TOKEN environment variable in the panel, so it never sits in your files.
  4. Start the bot and watch the console for your "Logged in as" line. Your bot shows as online in Discord.

Keep it online for good

  • Automatic restarts. Every bot crashes eventually: a Discord outage, an unexpected message, a bug. A host that restarts it automatically turns a crash into a few seconds of downtime.
  • Fix crash loops quickly. A bot that crashes the moment it connects reconnects over and over. Discord limits how often a bot can log in (1,000 times a day), and a bot that goes over has its token reset.
  • Catch your errors. Log errors instead of letting one bad command take the whole bot down, and check the console when something looks wrong.
  • Back up your data. If your bot stores anything, like levels or settings in a SQLite file, back it up regularly.

How much RAM does a Discord bot need?

Less than you'd think. A typical moderation, utility or fun bot in a handful of servers uses well under 256 MB, so a 1 GB plan is plenty. You need more for music bots, which process audio, and for bots in thousands of servers, which keep large caches. Once a bot reaches 2,500 servers, Discord requires sharding, which discord.js and discord.py both support.

Discord bot hosting on SkailarHost

Our Discord bot hosting runs discord.js and discord.py bots around the clock and restarts them automatically within seconds of a crash. Upload your code with the file manager or SFTP, set your startup command and environment variables in the panel, and your bot is online. Daily backups and DDoS protection are included, and plans start at $0.99/month.

FAQ

Can I host a Discord bot for free?

Yes, on your own PC or a free hosting tier, but expect downtime: the PC has to stay on, and free tiers usually sleep or limit hours. For a bot people rely on, a small paid plan is the reliable option.

Why is my bot online but not responding?

Usually a missing intent (Message Content for prefix commands), missing permissions in that channel, or slash commands that haven't been registered yet. The console normally shows which.

Do I need the Message Content intent?

Only if the bot reads the text of messages. Slash commands work without it. Bots in 100 or more servers need Discord's approval to use it.

Should I use discord.js or discord.py?

Whichever language you know. Both are mature, well documented and support everything a normal bot needs.

Keep your bot online 24/7

Discord bot hosting from $0.99/month, with discord.js and discord.py support, automatic restarts and daily backups.

Tags

#Discord#Discord Bots#discord.js#discord.py#Guides

Related Articles