.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.
How to set up the bot on your VPS
1
Create a user for the bot
2
Install Python and venv
- Ubuntu / Debian
- AlmaLinux / Rocky
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
requirements.txt, run ./venv/bin/pip install -r requirements.txt instead.5
Store the token in .env
os.environ["DISCORD_TOKEN"]. A minimal bot.py looks like this:6
Test it once
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
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:- 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.
- Run
npm ci(ornpm install) in the bot folder. - Use the systemd service above with
ExecStart=/usr/bin/node index.js, or keep the bot running with PM2.
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 withsystemctl 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.
Related guides
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:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026