Skip to main content
To host a Discord bot 24/7 on a Linux VPS, copy your bot’s code to the server, install its runtime (for example Python with a virtual environment), store the bot token in an .env file, and run the bot as a systemd service with Restart=on-failure. systemd keeps it running after you close SSH, restarts it if it crashes and starts it at boot.

Before you start

  • You need a bot application and token from the Discord Developer Portal, and working bot code on your PC.
  • A Discord bot connects out to Discord. You don’t need to open any inbound ports for it.
  • The examples use Python and discord.py, which needs Python 3.8 or newer. For a Node.js bot (discord.js), see the Node.js section further down.
Your bot token is a password. Never put it in your code, in Git or in a screenshot. If it leaks, reset it in the Developer Portal straight away.

How to set up the bot on your VPS

1

Create a user for the bot

Running the bot as its own user limits the damage if the bot is ever compromised.
2

Install Python and venv

3

Copy your code to the server

Switch to the bot user and clone your repository, or upload the files with SFTP:
4

Create a virtual environment and install packages

If your project has a requirements.txt, run ./venv/bin/pip install -r requirements.txt instead.
5

Store the token in .env

In your code, read it with os.environ["DISCORD_TOKEN"]. A minimal bot.py looks like this:
6

Test it once

When it prints Logged in as …, stop it with Ctrl+C and type exit to return to your sudo user.

How to run the bot 24/7 with systemd

1

Create the service file

2

Start it and enable it at boot

How to check it worked

The status shows active (running), and the log shows Logged in as …. Your bot is online in Discord. Press Ctrl+C to stop following the log.

How to update the bot

How to run a Node.js bot

For discord.js and other Node.js bots:
  1. Install the Node.js version your library requires. discord.js lists it on discord.js.org. See install Node.js and run apps with PM2.
  2. Run npm ci (or npm install) in the bot folder.
  3. Use the systemd service above with ExecStart=/usr/bin/node index.js, or keep the bot running with PM2.
Check the real path to node with which node, because installs through nvm put it elsewhere.

Frequently asked questions

Do I need to open a port for my Discord bot?

No. The bot opens an outgoing connection to Discord’s gateway. You only need an open port if your bot also runs a web server, for example for a dashboard or webhooks.

Why does my bot stop when I close PuTTY?

Programs started in an SSH session end when the session closes. Run the bot as a systemd service (above), or at least inside tmux.

How much RAM does a Discord bot need?

It depends on the library, the number of servers the bot is in and features such as music or caching. Check real use with systemctl status discord-bot, which shows the service’s memory use, and see check memory usage.

Can I run the bot in Docker instead?

Yes. Build an image with your code, pass the token with --env-file .env and start it with --restart unless-stopped. See essential Docker commands.

VPS and dedicated server guides

Every guide in this section.

Create a systemd service

Every option in a unit file.

Read logs with journalctl

Find out why the bot crashed.

Node.js and PM2

For discord.js bots.

Deploy a Python app with Gunicorn

If your bot has a web dashboard.

Checked against the official discord.py documentation on 4 November 2026; virtual environment, discord.py 2.7.1 install, the example bot and the systemd unit syntax tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026