How to keep a Discord bot online 24/7

A bot is a program, and it is online only while that program runs. Close the terminal on your PC and the bot goes offline with it. A bot you coded yourself belongs on a small rented server with a process manager. A bot without your own code can be hosted for you. Free code hosts sit in between, and most of them come with a catch.

Updated 18 Νοεμβρίου 20269 min read

On this page

The short version

  • A bot you coded needs a machine that never sleeps, usually a small rented server (VPS) with a process manager such as pm2.
  • Free tiers of code hosts tend to sleep, expire or change their terms. They are fine for experiments. A community shouldn't depend on them.
  • A bot you set up on SCNX is hosted by us from the moment you create it. SCNX can't run your own code.

What you need

  • For your own code: a rented Linux server and some patience with the command line
  • For a hosted bot: a Discord account and a server you own

Why a bot goes offline

Your bot holds an open connection to Discord. Messages, joins and button presses arrive over that connection, and the bot's answers go back the same way. When the program stops, the connection closes and Discord shows the bot as offline a little later.

The program stops for ordinary reasons: the computer goes to sleep, Windows installs an update, the internet drops for a minute, or an error crashes the code and nobody starts it again. Keeping a bot online means solving two things: a machine that is always on, and something that restarts the program when it falls over.

Where a bot can run

Places to run a Discord bot, compared
CostThe catch
Your own computerElec­tricityOffline whenever the PC sleeps, updates or loses its connec­tion
Free tier of a code hostNothingSleeps when idle, runs out of free hours or disap­pears
Rented server (VPS)A small monthly feeYou install, update and watch it yourself
Hosted bot on SCNXFree on our Starter planNo own code. You work with modules and custom commands

Your own computer is the right place while you are still writing the bot. For a community that expects the bot at three in the morning, it is one of the other three.

Free code hosting, and what breaks

Older tutorials send you to free tiers of general code hosts. Many of those offers are gone. Heroku ended its free plans in November 2022, and Replit removed its Always On feature at the start of 2024. What is left usually comes with one of these problems:

The project sleeps when idle
Free web hosting wakes a project when someone visits its address. A Discord bot has no visitors. It waits on its connection to Discord, so once the host puts it to sleep nothing wakes it again. Workarounds that ping the project every few minutes last until the host changes its rules.
The free hours or credits run out
Some hosts give you a monthly budget of hours or a one-time trial credit. A bot that runs all month uses about 730 hours, which is more than most free budgets.
Files don't survive a restart
On many free tiers the disk is wiped whenever the project restarts. A bot that keeps levels or warnings in a local file starts from zero each time, unless you move the data to a hosted database.
You share an address with strangers
Discord limits requests per IP address as well as per bot. On a shared free host, other people's bots use the same address, and their mistakes can slow yours down.

None of this makes free hosting useless. It is fine for learning and for a bot only your friends use. Read the current terms before you build a community on it, because they change often.

If you wrote the code: a VPS with pm2

For a bot you programmed, a small virtual server is the dependable answer. The smallest plan of most providers is enough for a bot on a handful of servers and costs a few euros or dollars a month. The steps below are for Ubuntu or Debian and are the same with every provider.

  1. Rent the server and update it

    Pick a small Linux plan, log in over SSH and run sudo apt update && sudo apt upgrade. Create a normal user for the bot so it doesn't run as root.

  2. Install the runtime and copy your code

    That is a current LTS release of Node.js for discord.js, or Python 3 for discord.py. Copy the project with git clone and install its dependencies with npm install or pip install -r requirements.txt.

  3. Keep the token out of the code

    Put the bot token in an environment variable or a .env file, and list that file in .gitignore. A token in a public repository is found within minutes. Discord resets tokens it spots on GitHub, and your bot stays offline until you enter the new one.

  4. Start the bot under a process manager

    Install pm2 with npm install -g pm2, then run pm2 start index.js --name bot. For Python it is pm2 start bot.py --name bot --interpreter python3. pm2 restarts the bot whenever it crashes.

  5. Make it survive a reboot

    Run pm2 startup and execute the command it prints, then pm2 save. Skip this step and the bot stays offline after the next reboot of the server until someone logs in.

  6. Check the logs and plan for updates

    pm2 logs bot shows what the bot printed before it crashed. The system, the runtime and your libraries need updates from time to time. Plan an hour a month, and keep a copy of your database somewhere else.

A systemd service does the same job as pm2 and is already on the server. Use whichever you are comfortable with. What matters is that something restarts the bot after a crash and after a reboot.

One Discord setting trips up most first deployments: if your code asks for the members, presence or message content intents, they have to be switched on under Privileged Gateway Intents on the Bot page of the Developer Portal. Otherwise the bot quits at login with a disallowed intents error.

If you have no code: a hosted bot

A bot you create on SCNX runs on our servers in Europe from the first minute. You don't install or upload anything. The parts of the VPS list above still exist, we just do them:

Crashes
If the bot's process crashes, the host system restarts it. The status card shows that while it happens.
Updates
When a new version of the bot is out, the status card tells you. Update bot installs it. The bot restarts and is offline for a moment.
Changes without downtime
After changing settings you use Reload configuration. The bot picks them up and stays online.
Logs
Log and Error-Log on the status card show what the bot did and why something failed, for example a missing permission in a channel.
Where it runs
The status card names the server your bot runs on, and you can move it to another one of our Bot-Hosts from there.
scnx.app
The bot status card in the SCNX dashboard: Lantern is online, with buttons to reload the configuration, restart or stop the bot.
The status card of Lantern, the bot on our test server.

Screenshot from our test server. Your dashboard may look different.

What you give up is the code. You can't log in to the machine or run your own program. Features come from the bot's modules and from custom commands you build in the dashboard. We have been hosting bots this way since 2020.

Your own code or a hosted bot

A bot you coded on a VPS compared with a hosted bot on SCNX
Your code on a VPSHosted bot on SCNX
FeaturesWhatever you can write65+ modules and custom commands
SetupServer, runtime, process managerA token and a few clicks
Crashes and updatesYours to handleHandled by us
CostA monthly server feeFree on our Starter plan, with an ad check-in
Public bot for many serversPossibleNo, one bot per commu­nity

What free means on SCNX

Our Starter plan hosts your bot 24/7 and costs nothing. It is paid for by ads. Every 14 days someone on your team opens the dashboard and watches a short ad video, and that check-in keeps the bot online. If nobody does, the bot goes offline until the video has been watched.

On our paid plans the bot stays online for as long as the plan is active, and the check-in and the ads are gone. The plans page compares them.

If your bot is offline right now

For a bot on your own server, start with pm2 status and pm2 logs. For a bot on SCNX, open its status card. The usual causes:

The process crashed and nothing restarted it
On a VPS this means the process manager is missing or was not saved. Go back to the pm2 steps. On SCNX the host restarts the bot by itself.
The token is no longer valid
Someone reset it in the Developer Portal, or Discord did because it leaked. Create a new token. On a VPS, put it in your environment file and restart. On SCNX, the status card shows Discord rejected your bot token with a button to enter the new one.
The intents are switched off
The bot asks for privileged intents that are off in the Developer Portal. Turn them on under Privileged Gateway Intents and start the bot again.
The free plan ran out
On our Starter plan the bot stops when the ad check-in was missed. Watch the short video in the dashboard and start the bot.
The bot was removed from the server
A bot that was kicked can't do anything. On SCNX the dashboard says Your bot was removed from your server and offers the invite again.
Discord itself has a problem
If several bots are offline at once, check discordstatus.com before you change anything.

Coming from a bot you coded

SCNX does not run your own code, so you can't upload an existing bot. What you can do is rebuild its features: most of the common ones exist as modules, and your own logic can be built with Custom Commands V3, which is in beta.

If an AI assistant wrote your bot and you are the one keeping it alive, the page on coming from AI-written bot code goes through the differences. And if you enjoy running your own server, there is nothing wrong with staying on a VPS.

Common questions

Can I host a Discord bot for free?
Yes, with conditions everywhere. On SCNX, our Starter plan hosts your bot for free and asks for a short ad video every 14 days. Free tiers of code hosts usually limit hours or put idle bots to sleep.
Can I upload my own bot code to SCNX?
No. SCNX hosts the bots you create on SCNX. For your own code you need a server of your own.
Do I have to leave my computer on?
Only if the bot runs on it. A bot on a VPS or on SCNX keeps running when your computer is off.
Can I host a bot on a Raspberry Pi at home?
Yes, a bot for one community runs fine on one. It is online as long as the Pi has power and your home internet works, and you still need a process manager such as pm2 so it restarts after a crash or a power cut.
Why does Discord show my bot as offline although it is running?
Discord can take a few minutes to update the status after a start or a stop. If the dot stays grey for longer, the bot is not connected. Check the logs for a token or intents error.
Does a bot on SCNX stay online when I close the dashboard?
Yes. The dashboard is only where you change settings. The bot runs on our servers whether you are logged in or not.
What happens if a host has a problem?
On SCNX, your bot's configuration and data are backed up and we restore them if a host fails. Outages and maintenance are announced on our status page.

Start with a free bot

Log in with Discord, add your server and create your bot. The dashboard walks you through each step.

Get started for free

Free on our Starter plan. A short ad video every 14 days keeps the bot online.