To host a Discord bot 24/7, move the working Node.js project to a VPS, run it as an unprivileged user, and put PM2 in charge of the process. Save PM2’s process list and install the startup service it generates. The bot will then stay up when you close SSH, restart after a process crash, and return after the server reboots. This is resilient operation, not a promise of 100% uptime: the VPS, network, Discord, or the application itself can still fail.
This runbook starts with a working discord.js bot and targets Ubuntu 24.04 LTS. If you are still choosing a runtime, start with our discord.js vs discord.py comparison; this guide focuses on operating an existing Node.js bot.
What keeps a Discord bot running
A bot using the Discord Gateway maintains a persistent WebSocket, sends heartbeats, and reconnects or resumes when required. discord.js handles that protocol. PM2 sits at a different layer: it detaches the Node.js process from your terminal, restarts it after an exit, and can restore it during system startup.
The responsibilities are separate: PM2 handles a closed SSH session, a crash, and a reboot; the library handles Gateway recovery. PM2’s “online” state proves only that a process exists, so the runbook later adds a Discord-client readiness check.
Prerequisites and sizing guidance
You need SSH access through a sudo-capable administration account, a registered Discord application, a valid bot token, and either a repository or project copy containing package-lock.json. Use an actual bot user. Discord’s OAuth2 and bot documentation says developers must not automate normal user accounts, commonly called self-bots.
| Resource | Evaluation baseline | Reasons to scale up |
|---|---|---|
| CPU | One vCPU may be enough to evaluate a small text bot. | CPU-heavy commands, encryption, image work, browsers, and voice change the profile. |
| Memory | Roughly 1 GB gives the OS and a small bot more breathing room than a minimum-size instance. | Large guild counts, caches, a local database, voice, or sidecars require measurement and more headroom. |
| Disk | Allow for the OS, at least two releases, dependencies, and logs. | Generated files, SQLite, audio, and long log retention increase the requirement. |
| Network | Stable outbound HTTPS/WSS access to Discord and any services the bot calls. | Inbound webhooks, a dashboard, or OAuth2 callbacks add ports, TLS, and reverse-proxy work. |
These figures are starting points, not universal minimums. Measure CPU, memory, storage, and latency under your own workload before committing to a plan.
1. Prepare Ubuntu and isolate the bot user
Connect with the administration account. Install the small set of tools used below and create a dedicated system identity. Neither the bot nor its PM2 daemon should run as root.











