Skip to content

How to Host a Discord Bot 24/7

A Discord bot only stays online for as long as its process is running somewhere. If that somewhere is your own laptop, the bot goes offline the moment you close it. This guide covers what actually keeps a Node.js (discord.js) bot running independently: hosting, token security, and what auto-restart does and doesn't fix.

1

Step 1: Get your bot token

From the Discord Developer Portal, create an application (or use an existing one), add a Bot user, and copy the token. Treat this token like a password: anyone with it can control your bot completely.

2

Step 2: Start a Discord Bot server

Create a Discord Bot (Node.js) server from your dashboard. It comes up running a minimal placeholder script by default, so you'll see it online in the console immediately, before you've uploaded anything of your own.

3

Step 3: Upload your bot code

Use the panel's file manager or the Browser IDE to upload your bot's files, replacing the placeholder index.js with your actual bot code. If your bot uses npm packages, upload package.json listing them; the panel installs dependencies as part of starting the server.

Keep your package.json's "main" field pointing at your actual entry file. If it doesn't match the file you uploaded, the server won't find it on boot.

4

Step 4: Set your token as an environment variable

In your server's startup configuration, set your Discord token as an environment variable rather than hardcoding it in your bot's source. Reference it in your code as process.env.DISCORD_TOKEN (or whatever variable name you configured).

client.login(process.env.DISCORD_TOKEN);

This matters even for a private bot: source files sometimes end up shared, backed up, or pasted somewhere without you intending it to be public.

5

Step 5: Start the bot and confirm it connects

Restart the server from your panel and check the console log. discord.js logs a ready event once it successfully connects to Discord's gateway. Check your bot shows online in Discord itself: the console can say connected before Discord's own presence indicator catches up by a few seconds.

6

Step 6: Leave it running

That's the actual point of hosting: the bot keeps running, and keeps its gateway connection open, independent of your own computer being on. Auto-restart handles a crash; you don't need to babysit the console unless you're actively debugging something.

Ready to get your bot off your laptop?

Start a free Discord Bot trial on Zeros Host: no credit card required. Servers run on UK and EU infrastructure with auto-restart on crash.

Start your free Discord bot server →

Frequently asked questions

Why does my Discord bot go offline when I close my laptop?

Because discord.js keeps a persistent WebSocket connection open to Discord's gateway for as long as the process is running. Close the terminal, close the laptop, or lose your home internet, and that connection drops: the bot shows offline in every server it's in, instantly, for everyone. There's no way around this while the bot runs on a personal machine: it needs a process that stays running independently of your own device.

What's the difference between hosting a bot and hosting a game server?

Mechanically, less than you'd think: both are a long-running process on a server with restart-on-crash and log access. The real difference is resource shape: a Discord bot for a small-to-medium server typically needs a fraction of the RAM and CPU a game server does, since it's mostly waiting on Discord's gateway and occasionally handling a command, not simulating a game world in real time.

Do I need to know how to code to host a bot?

You need bot code to run, either your own or an open-source bot you've configured. Hosting itself doesn't require writing code: you upload your bot's files, set your token as an environment variable, and start it. If you're building your own bot from scratch, that's a separate skill (discord.js and Node.js knowledge) from hosting it once it's built.

How do I keep my bot token safe?

Never commit it to your code or paste it in Discord. Set it as an environment variable in your panel's startup configuration instead, and read it in your code with something like process.env.DISCORD_TOKEN. If you ever paste your token somewhere public by accident, regenerate it immediately from the Discord Developer Portal: a leaked token lets anyone control your bot.

What happens if my bot crashes?

A crash from a bug in your own code will take the bot offline until something restarts it. Zeros Host's auto-restart brings a crashed process back up automatically rather than leaving it down until you notice, but it can't fix the bug that caused the crash: check your console log for the stack trace after a restart to find what actually went wrong.