Host your Discord Bot 24/7 (BEST Budget Server)
There are many ways to host your Discord bot. In this article I will show you the BEST method if you want a budget server with fantastic specs:
- 8 GB RAM
- 4 vCPUs
- 200 GB SSD
- 35 TB Bandwidth
- $6.99/mo
Step 1 — Signing Up
Visit https://wornoffkeys.com/bestvps and keep everything default aside from the region. I live in the Western United States so I selected US West for my region, but select whatever region works for you.
You will then be sent to a page where you can enter your account and billing information. Fill out those forms and move to the next step.
Step 2 — Installing the OS
At this stage you should be sent to a page similar to this one:
It mentions it could take up to 3 hours but most of the time this will only take a few seconds. You will get an email with a link to https://my.contabo.com/vps. Go ahead and click on that to visit the VPS dashboard. You should see an area that lists your new servers similar to this one:
Click on the “Install Instance” button. You will be sent to this screen:
Note: This hosting provider uses an “admin” user instead of a “root” user.
Select your desired operating system from the “Standard Image” dropdown. I will use Ubuntu 21.10 for this tutorial, but use whatever works best for you.
You can now create a password by clicking in the “Password For User Admin” field, then select “Add and Store Password”.
You can enter your own password or generate one with the keypad icon. Make sure to write down your password because you will need it to login to your server.
Step 3 — Connecting to Your VPS
When connecting I recommend using the free software Bitvise which you can download here: https://www.bitvise.com/download-area.
Once you install it you can open it and you should get a window like this:
Enter your VPS server IP (found at https://my.contabo.com/vps) as the “Host”. Enter “22” as the “Port”. Enter “admin” as the “Username”. For the “Initial method” select “password” and check the “Store encrypted password in profile” checkbox. Finally paste in your password that you created earlier.
Click on “Save profile as” so you can easily login without entering all of this information next time. Click “Log in” at the bottom and “Accept and Save” if you are prompted to do so.
You should finally be logged into your server with two new windows. The black screen is your terminal where you can run commands, the other window is your FTP client to upload and manage files.
Step 4 —Installing Node.JS
To run a Discord bot we need Node.JS version 16.6 or newer. By default your VPS won’t have Node installed at all, so we need to install it by running the following commands:
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install -y nodejs
Then finally check to make sure you Node.JS v16.6 or newer:
node -v
Depending on when you’re reading this the version number might be different. As long as you have 16.6 or newer then your Discord bot will work.
Step 5 — Uploading and Running Your Bot
In your console run the following command to make a new folder and navigate into it:
mkdir bot && cd bot
In your FTP client refresh and navigate into the new “bot” folder:
Then select everything in your bot folder excluding node_modules and upload it into the bot folder. In the screen shot above that would be the “.env”, “index.js”, “package-lock.json”, and “package.json” file. Do not upload your node_modules folder.
In your terminal you can now install your bot’s dependencies with the following command:
npm install
Finally we can install a process manager called pm2 to run our bot without us being logged into the VPS:
sudo npm install -g pm2
You can then run the following commands to start your bot:
pm2 start index.js
How to list all running processes:
pm2 list
How to restart a specific process:
pm2 restart <id>
Example with a process that has an ID of 0 (the default)
pm2 restart 0
How to stop and start a process by ID:
pm2 stop <id>
pm2 start <id>
Once your bot is running with pm2 you can close your terminal. It will now be running 24/7.