Skip to main content
Running a Discord bot on your Opus Host VPS means it stays online 24/7 even when your computer is off. This guide covers deploying a Node.js or Python bot and keeping it alive using PM2 or systemd, so your bot automatically restarts after crashes or reboots.

Choose Your Language

1

Install Node.js

Add the NodeSource repository and install Node.js 20:
2

Upload or clone your bot files

You can upload files using the File Manager in the Opus Host panel, transfer them with SCP, or clone directly from GitHub:
3

Install dependencies

4

Test the bot

Run the bot once to make sure it connects and responds correctly before setting it up as a background service:
Press Ctrl + C to stop it when you’re ready to move on.

Keep Your Bot Running with PM2 (Node.js)

PM2 is a process manager for Node.js applications. It restarts your bot automatically if it crashes and can start it on system boot.
1

Install PM2 globally

2

Start your bot with PM2

3

Enable auto-start on reboot

Generate and apply the startup hook so PM2 and your bot survive a server restart:
Run the command that pm2 startup prints (it will look like sudo env PATH=... pm2 startup systemd -u root --hp /root).
4

Monitor your bot

Check the current status of all PM2 processes:
Tail the live logs for your bot:

Keep Your Bot Running with systemd (Python or Node.js)

systemd is built into every modern Linux system and is a great choice if you prefer not to install PM2, or if your bot is written in Python. Create a service unit file at /etc/systemd/system/mybot.service:
For a Node.js bot, change ExecStart to /usr/bin/node /root/mybot/index.js. Then enable and start the service:
Check that the service is running:
Store your bot token in a .env file rather than hard-coding it in your source code. Use the dotenv npm package for Node.js or python-dotenv for Python to load the file automatically at startup.
Never share or commit your bot token to a public repository. If your token is ever exposed, regenerate it immediately in the Discord Developer Portal to prevent unauthorized access to your bot.