How to Host a Discord Bot 24/7 with Node.js or Python

Choose managed bot hosting or a VPS, deploy Discord.js or discord.py safely, and keep the process online with proper secrets, restarts, logs and monitoring.

Explore Bot HostingCompare Cloud VPS
HYEHOST mascot deploying a Discord bot to an always-online server

Running a Discord bot from a laptop is useful while you are writing commands, testing events and fixing bugs. It is not a reliable production setup. The bot stops when the device sleeps, restarts during updates, loses its connection, or moves between networks.

Hosting a Discord bot 24/7 means placing the process on infrastructure designed to stay online. For most bots, you have two sensible choices:

  1. Managed bot hosting when you want a simple deployment workflow, runtime controls, logs and a persistent environment.
  2. A VPS when you need full server control, multiple services, custom databases, reverse proxies, workers or a more complex application stack.

This guide covers both approaches, then explains the production basics that matter regardless of whether your bot uses JavaScript, TypeScript or Python.

What does a Discord bot need to run continuously?

Most Discord bots are modest workloads. A typical bot connects to the Discord gateway, receives events, runs command handlers and may call an API or database. CPU usage is often low outside bursts of activity. Reliability usually depends more on process management, secrets, logging and dependency updates than on raw server size.

Before choosing hosting, identify what your bot actually needs:

Requirement What it changes
A small moderation, utility or notification bot Managed bot hosting is usually enough.
Discord.js or discord.py only A Node.js or Python runtime is sufficient.
PostgreSQL, Redis, a web dashboard or background workers A VPS gives more flexibility.
Docker Compose and several services Use a VPS.
A custom domain and public webhooks Use a VPS or a managed platform with web service support.
Large music, media or AI workloads Start with a VPS and size it for the external services as well.

Do not size a server only for the bot process if it also runs a database, dashboard and queue worker. Those supporting services are often the real memory consumers.

Managed Discord bot hosting vs a VPS

Choose managed bot hosting when you want less server administration

Managed bot hosting is the faster route when the application is primarily a bot. You upload or connect a repository, choose the runtime, set the start command and manage environment variables. The platform handles the application container lifecycle.

This is a good choice for:

  • Discord.js, Eris, discord.py, nextcord and similar bots.
  • Community bots, ticket bots, moderation bots and role tools.
  • Bots that only need a few environment variables and a persistent files area.
  • Teams that want logs and restart controls without maintaining Linux themselves.

HYEHOST Bot Hosting supports Node.js, Python and Java runtimes, Git deployment, file management, logs, restart controls and a persistent static IPv6 address for each plan. That makes it a practical fit when a Discord bot does not need a full virtual server.

Choose a VPS when the bot is part of a larger stack

A VPS is a better fit when the bot is only one part of the application. You can run Docker, a database, a web dashboard, monitoring, scheduled jobs and private networking on the same server or split services across multiple VMs.

Use a VPS when you need to:

  • Run PostgreSQL, MySQL, Redis or MongoDB locally.
  • Deploy with Docker Compose.
  • Operate a public API or OAuth callback.
  • Host a website or admin panel alongside the bot.
  • Use Tailscale, private networking, custom firewall rules or your own monitoring stack.
  • Control the operating system, packages and update schedule.

For a basic Discord bot, a small Cloud VPS is normally sufficient. Increase RAM before CPU when adding a database or cache, and keep enough disk space for logs, backups and dependency updates.

Before you deploy: prepare the bot properly

There are a few mistakes that cause most first-time hosting failures. Fix them before uploading anything.

Keep the token out of your source code

Your Discord bot token is a secret. Anyone with it can impersonate the bot. Do not commit it to GitHub, paste it into a public support message or put it directly in index.js or main.py.

Use an environment variable instead.

For Node.js:

import { Client, GatewayIntentBits } from 'discord.js';

const token = process.env.DISCORD_TOKEN;
if (!token) throw new Error('DISCORD_TOKEN is not configured');

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

For Python:

import os
import discord

token = os.environ.get("DISCORD_TOKEN")
if not token:
    raise RuntimeError("DISCORD_TOKEN is not configured")

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

Add .env to .gitignore. Use your host's environment-variable interface to store the real value. If a token is ever exposed, reset it in the Discord Developer Portal immediately.

Verify the start command locally

Know the exact command that starts your bot before deploying it:

# Node.js
npm ci
npm start

# Python
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
python main.py

For Node.js, npm ci is preferable in production because it installs the exact versions in package-lock.json. For Python, pin dependencies in requirements.txt or a lock file so a later package release does not unexpectedly change the runtime.

Enable the Discord intents your code needs

A bot can connect successfully but still appear broken if the required gateway intents are disabled. Check both places:

  1. Your code must request the intent.
  2. The Discord Developer Portal must allow privileged intents such as Message Content, Guild Members or Presence when your bot uses them.

Only enable intents you genuinely need. It keeps the bot easier to reason about and reduces unnecessary event traffic.

Deploying a Node.js Discord bot

Managed bot hosting workflow

The usual workflow is:

  1. Create a Node.js bot service.
  2. Connect a Git repository or upload the project files.
  3. Set the install command to npm ci where a lock file exists.
  4. Set the start command, commonly npm start or node src/index.js.
  5. Add DISCORD_TOKEN and any database or API variables in the environment settings.
  6. Start the service and watch the logs until the bot reports that it is ready.

Avoid using a development command such as nodemon in production. It consumes extra resources and can make restart behaviour harder to diagnose.

VPS workflow with systemd

On Debian or Ubuntu, create a dedicated non-root user, put the code in that user's home directory and install dependencies. Then add a systemd service:

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

[Service]
Type=simple
User=discordbot
WorkingDirectory=/home/discordbot/app
EnvironmentFile=/home/discordbot/app/.env
ExecStart=/usr/bin/npm start
Restart=always
RestartSec=5
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

Then enable it:

sudo systemctl daemon-reload
sudo systemctl enable --now discord-bot
sudo systemctl status discord-bot

View logs with:

journalctl -u discord-bot -f

This is much more reliable than leaving an SSH session open with node index.js running in a terminal.

Deploying a Python Discord bot

The same principles apply to discord.py, nextcord and pycord bots.

For managed hosting, choose Python, install from requirements.txt, set the start command to python main.py or the correct application entry point, then configure the token in environment variables.

For a VPS, use a virtual environment and point systemd at its Python binary:

[Service]
User=discordbot
WorkingDirectory=/home/discordbot/app
EnvironmentFile=/home/discordbot/app/.env
ExecStart=/home/discordbot/app/.venv/bin/python main.py
Restart=always
RestartSec=5

If the bot uses a web framework for interactions or OAuth, put that web process behind a reverse proxy with HTTPS. Keep the Discord gateway bot and the web service as separate processes so one can restart without taking down the other.

How to keep a Discord bot online

Use a restart policy, but do not hide repeated crashes

An automatic restart is essential, but an endless crash loop is still an incident. Use systemd Restart=always or your hosting platform's restart control, then review the logs if restarts become frequent.

Useful things to log at startup:

  • Runtime and dependency version.
  • Bot username and application ID, but never the token.
  • Connected guild count if appropriate.
  • Database connection status.
  • Whether required environment variables are present.

Add a simple health endpoint for larger bots

If your bot already has a web server, expose a minimal authenticated or private health endpoint that confirms the process is alive and, if useful, whether the Discord client is ready. Do not expose internal metrics or secrets publicly without access control.

Watch memory use and logs

Common causes of a bot becoming unreliable over time include:

  • Unbounded caches or message history held in memory.
  • Repeated API retries without a backoff.
  • A database pool that is never closed.
  • Huge debug logs consuming disk space.
  • Updating a dependency without testing the new version.

On a VPS, monitor memory, disk usage and service restarts. On managed bot hosting, check runtime logs and the plan's CPU and memory view. If a bot is consistently near its memory limit, move it to the next plan before it begins restarting.

Common Discord bot hosting problems

The process starts and immediately exits

Read the first error in the log. Typical causes are a missing environment variable, an incorrect entry file, a package not listed in dependencies, or using a Node.js version incompatible with the project.

The bot is online but commands do not work

Check that slash commands have been registered, the bot has been invited with the correct scopes, and the required gateway intents are enabled. Also verify the bot has permission to respond in the channel.

Cannot find module or ModuleNotFoundError

Make sure the dependency is declared in package.json or requirements.txt. Reinstall dependencies from the project directory. Do not rely on packages installed globally on a development computer.

The bot disconnects regularly

Look for gateway errors, network failures and rate-limit messages in the logs. Confirm the process manager is restarting the bot, then investigate the underlying exception rather than repeatedly restarting it by hand.

The bot works locally but not on the host

Compare the runtime version, environment variables and install command. Local projects often depend on an uncommitted .env file or a globally installed package that the host cannot see.

A practical production checklist

Before calling a bot production-ready, confirm that you can answer yes to each point:

  • The token is stored as an environment variable and is not committed to Git.
  • Dependencies are pinned and installed from the lock file or requirements file.
  • The process starts automatically after a restart.
  • Logs are easy to access and do not contain secrets.
  • Privileged intents are enabled only when required.
  • A backup exists for the database and any important persistent files.
  • You know how to rotate the token and redeploy the bot.
  • You have checked the bot's permissions in a real test server.

Hosting a Discord bot with HYEHOST

For a straightforward Node.js, Python or Java Discord bot, HYEHOST Bot Hosting provides the simpler path: pick a runtime, deploy from Git or files, configure environment variables and use the panel for logs, restarts and activity.

Choose a HYEHOST Cloud VPS when the bot needs more than a single runtime: Docker Compose, a database, Redis, a web dashboard, a custom domain, private networking or other self-hosted services. The panel provides console access, reinstall controls, networking and usage visibility for the server itself.

The right choice is the one that keeps your deployment understandable. Start with managed bot hosting for a focused bot, or a VPS when the bot is part of a wider application stack.

Frequently asked questions

Can I host a Discord bot for free?

Some free services exist, but they commonly sleep, limit runtime or impose restrictive resource limits. A paid always-on hosting plan is generally more suitable for community bots, moderation tools and anything users expect to respond reliably.

How much RAM does a Discord bot need?

A simple bot can run in a few hundred megabytes. Add more memory when you use a database, cache, image processing, music playback, AI APIs or a web dashboard. Monitor actual use rather than guessing from the language alone.

Is Node.js or Python better for Discord bots?

Both are good choices. Use the language and library your project already uses well. Discord.js is popular in the JavaScript ecosystem; discord.py is a mature Python choice. Reliability comes from deployment discipline more than language choice.

Do Discord bots need open ports?

Most gateway-based bots make an outbound connection to Discord and do not need an inbound port. You only need public ports when you add webhooks, an OAuth callback, a dashboard or another web service.

Can I host several Discord bots on one VPS?

Yes. Use separate service users or separate systemd services, environment files and log streams. Docker Compose is also useful when each bot has its own dependencies and you want repeatable deployment.