How to host a Discord bot 24/7

To host a Discord bot 24/7, run it on a machine that stays powered on and connected to the internet. Use a process manager for reboot and crash recovery. A VPS, Raspberry Pi or bot host can do this.

Updated

Choose where the bot runs

A bot host handles the machine and gives you a console, file tools and resource limits. On discordbothost, each bot has its own container and idle bots do not sleep. Free provides 256 MB RAM and 1 GB disk, but stops after 7 days until renewed. Paid plans start at $0.99 a month without weekly renewal. Bots restart automatically after a crash. Repeated crashes pause restarts; check the console before starting again.

A VPS gives you operating system control. A Raspberry Pi also depends on home power and internet. You maintain updates, access and backups. Read bot hosting vs a VPS before choosing.

A web platform may stop idle services. Check its background-worker and sleep rules. Discord connections may not count as incoming web traffic; HTTP pings cannot fix crashes. See the Replit migration guide.

Deploy on a bot host

Start with a project that already works locally and an application in the Discord Developer Portal. Invite its bot to a test server with the permissions it needs.

  1. Choose the discord.js, discord.py or JDA template. Keep its included hello-world until you have checked the token and runtime.
  2. Set BOT_TOKEN privately in the panel variables. Read it from your code; never commit it to GitHub.
  3. Upload the project with the file manager or SFTP, or connect a public GitHub repository and branch. Free supports public repositories within its disk limit; private repository tokens require a paid plan.
  4. Set the entry file and runtime dependencies using the discord.js, discord.py or JDA instructions.
  5. Stop your local copy, start the hosted bot, check its ready message and test a command in Discord. You can then close your computer.

Read GitHub deployment for webhook setup. Keep an independent copy of source and data.

Self host on Linux with systemd

These commands target Ubuntu or Debian with systemd and sudo access, including compatible Raspberry Pi distributions. Start with a working bot and a runtime matching its discord.js requirements or discord.py requirements. The distribution's default Node version may be too old.

Prepare a service account and project

Run these once on a fresh setup. The service account keeps the bot separate from your login account.

Create the account and project directory
sudo useradd --system --user-group --home-dir /opt/discord-bot --shell /usr/sbin/nologin discordbot
sudo install -d -o discordbot -g discordbot -m 0750 /opt/discord-bot

Copy the project into /opt/discord-bot and give discordbot ownership. Exclude local node_modules, virtual environments and secrets. Inspect third-party code before installing dependencies as the service account.

For a Node project with package-lock.json:

Install Node dependencies
cd /opt/discord-bot
sudo -u discordbot npm ci --omit=dev
command -v node

If the project needs a build, run its documented build with the required development dependencies first. For Python, install the distribution's python3-venv package, then:

Create a Python virtual environment
cd /opt/discord-bot
sudo -u discordbot python3 -m venv .venv
sudo -u discordbot .venv/bin/python -m pip install -r requirements.txt

Store the token outside the repository

Create a root-owned environment file, then edit it locally on the server:

Create the private environment file
sudo install -m 0600 /dev/null /etc/discord-bot.env
sudoedit /etc/discord-bot.env

Enter BOT_TOKEN followed by an equals sign and your bot token on one line, without an export prefix. Do not overwrite an existing file during an update. Use process.env.BOT_TOKEN in Node or os.environ["BOT_TOKEN"] in Python. If your code expects DISCORD_TOKEN instead, use that name consistently. Follow token and environment variable setup if login fails.

Create the service

Run sudoedit /etc/systemd/system/discord-bot.service and add this unit. Replace /usr/bin/node with the absolute path printed by command -v node and index.js with your entry file. The runtime must be accessible to discordbot; a runtime inside your personal home directory may be inaccessible.

/etc/systemd/system/discord-bot.service
[Unit]
Description=Discord bot
Wants=network-online.target
After=network-online.target
StartLimitIntervalSec=300
StartLimitBurst=5

[Service]
Type=simple
User=discordbot
Group=discordbot
WorkingDirectory=/opt/discord-bot
EnvironmentFile=/etc/discord-bot.env
ExecStart=/usr/bin/node /opt/discord-bot/index.js
Restart=on-failure
RestartSec=10
NoNewPrivileges=true
PrivateTmp=true

[Install]
WantedBy=multi-user.target

For Python, replace the ExecStart line with ExecStart=/opt/discord-bot/.venv/bin/python -u /opt/discord-bot/bot.py, adjusting the filename. Use only one ExecStart line. systemd reads the environment file before switching to the service account.

Start the bot and test recovery

Stop any other copy using the same token, then:

Load and start the service
sudo systemd-analyze verify /etc/systemd/system/discord-bot.service
sudo systemctl daemon-reload
sudo systemctl enable --now discord-bot
sudo systemctl status discord-bot --no-pager
sudo journalctl -u discord-bot -n 50 --no-pager

Check the ready message and a real Discord command. Disconnect SSH and confirm the bot still answers. When convenient, reboot the machine and repeat that check. To test failure recovery in a test server, run sudo systemctl kill --signal=SIGKILL --kill-whom=main discord-bot and inspect the journal after the restart delay. This deliberately interrupts the bot. A manual systemctl stop does not trigger recovery.

Restart=on-failure restarts failed processes, not a process that exits successfully or stays running while disconnected. The unit limits repeated starts so a bad token cannot cause an endless rapid restart loop. Fix the first log error, then use sudo systemctl reset-failed discord-bot and sudo systemctl start discord-bot. See the systemd service reference for restart behavior.

When an online process still does not answer

Check permissions and intents in both code and the Developer Portal. Inspect memory, dependency errors and database connectivity. Let your Discord library handle normal reconnects; avoid wrapping login in an unbounded retry loop. Register slash commands through a separate deployment step rather than on every restart.

Use the offline troubleshooting guide and operating checklist for repeated failures. Back up persistent data and install system updates.

Try a free bot container or compare current plans if you want a panel for deployment instead of maintaining Linux.

Plans

  • FreeFree256 MB · Renew every 7 days
  • Starter$0.99512 MB · / month
  • Pro$1.991 GB · / month
  • Plus$3.492 GB · / month
See pricing

Questions

Does 24/7 hosting mean my bot can never go offline?

No. Code errors, maintenance, network interruptions, and Discord disconnects can interrupt a bot. Check logs and keep a recovery copy of your data.

How do I self host a Discord bot?

Use a Linux machine that stays powered on, install the runtime and dependencies, store the bot token privately, and configure a systemd service to start after reboot and recover from failures. At home, your bot also depends on your power and internet connection.

Does a Discord bot need a public port or a website?

A Gateway bot connects out to Discord and does not need an incoming public port just to receive Gateway events. HTTP interactions, dashboards and other web features have their own hosting requirements.

Can I close my laptop after deploying?

Yes. Once the server is running your bot, your laptop does not need to stay on. Stop the local copy and test the hosted bot in Discord.