Having a Discord bot that’s up and running 24/7, 365 days a year is the dream.
It doesn’t matter if you just want to have your bot 100% available for your server’s users, or if you want to grow and support hundreds of servers in the future.
No matter what you’re going after, hosting your own Discord bot is the way to go!
In this detailed Discord bot hosting guide, we’re going to walk through the exact steps to get your bot up and running 24/7 in under an hour.
We’ll go over the best Discord bot hosting methods, and then walk through how to set up your very own reliable bot hosting.
After reading this guide you’ll know all the tricks to get a bot deployed on a VPS (Virtual Private Server), hosted, and live in under an hour, and best of all you’ll be able to replicate this process for years to come.
Here’s How You Get Your Bot Up and Running 24/7
Setting up your own bot hosting might seem complicated, but it’s actually much easier than it looks. The key is to understand what we’re actually doing step by step, and not just blindly following along without thinking or reading the explanations.
This is exactly why we go through each step in-depth, letting you actually understand and learn why we’re doing things the way we are.
What this guide will cover
We’re going to start by going over how to set up a JavaScript / Node.js bot on your own VPS host and then talk through some alternative options like Amazon AWS, Google Cloud, and even how to host your own Discord bot on a Raspberry Pi.
Picking a reliable VPS host
The key to having solid reliable hosting for your bot is to use a well-known reputable third-party hosting provider. For the purposes of this guide, we’ll be using Vultr VPS (you can create an account here) due to its reliability, solid uptime, and low cost.
A good hosting provider will allow you to have:
- Reliable Uptime – I’ve been using Vultr as a VPS host for websites & bots for years, and have experienced 99.9% uptime as indicated by uptime analysis tools like Uptime Robot.
- Simple Control Panel – Navigating around your VPS control panel to change settings should be incredibly easy and simple. We’ll have detailed screenshots and steps for configuring your Discord bot in the coming sections, so you’ll be able to see how simple it is to navigate firsthand.
- DDoS Protection – If your server gets popular, there may be a third party that attempts to take it down through a distributed denial-of-service (DDoS) attack. Fortunately, Vultr VPS servers give you the option to add DDoS protection if you choose.
- Reliable Operating System – The most affordable, cost-effective, and efficient VPS server operating system (OS) for hosting your Discord bot is a Linux Server. Using Windows Server, for example, requires you to pay an extra licensing fee. By using a reliable Linux distribution like Ubuntu Server, you can get up and running and pay just a few dollars ($) per month.
- Frequent Backups – If something happens and you lose your data, having a backup will save you. A reliable VPS provider will offer backup options and an easy recovery mechanism.
- SSD Storage & NVMe – To ensure your server doesn’t have any bottlenecks and can handle a large number of requests, you’ll want to find a Discord bot host that offers fast storage through SSD (Solid State Drives) and NVMe (NVM Express Storage Access and Transport Protocol). The better your server’s hardware, the more it’ll resemble enterprise-grade hardware.
- Reliable Support Team – If you have any questions about your Discord bot hosting server, a dependable support team will save you from endless headaches and scrambling to find answers yourself. Usually, all you have to do is submit a support ticket for quick support.
- FTP Access & SSH Support – Most VPS hosts offer this right out of the box. FTP (File Transfer Protocol) will allow you to connect to your server and browse your files through a tool like FileZilla. SSH (Secure Shell) allows you to connect to your server through a terminal to install software, send commands, and configure various server settings.
Dedicated Server vs. Shared Server
Using a VPS for hosting your discord bot will allow you to fully utilize the server resources you pay for, without sharing them among multiple web applications or websites.
A shared hosting server is slower and more sluggish when compared to a dedicated server.
By following the VPS setup process in this guide, you’ll be able to set up a crisp and fast VPS host that makes your bot run surprisingly quickly.
Location, Location, Location
Since you have complete control over your VPS server’s location, when we get to the section of this guide where you choose your server’s zone, I’d recommend choosing one close to where most of your Discord users live.
If that’s not possible, or if your audience is worldwide, I’d go with a centrally located server with low ping and excellent connection speeds.
If your audience is global, it’s never a bad idea to choose a major city in the United States; In my personal experience, this has been both reliable and quick for all of my servers.
For this guide, we’ll be going over a complete Discord bot hosting setup on Vultr.
I’ve used Vultr for five years and have never had uptime or reliability issues.
Ready to dive in? Let’s do it!
The Best Discord Bot Hosting Method
The best method for hosting Discord bots and having near 100% uptime is a third-party Virtual Private Server (VPS).
A Virtual Private Server is, as its name suggests, a “virtual” server that’s up and running 24/7 from your chosen location worldwide.
Even though it requires a little bit of setup to get up and running, the result is well worth it.
I like VPS hosting because it’s both extremely affordable (think, a few dollars a month) and super reliable (you won’t have to worry about your server going down, practically ever).
The flexibility you have with your own Virtual Private Server is completely unheard of when you compare it to having your own self-hosted solution or even using a managed Discord bot host.
In the next few sections, we’re going to walk through the process of setting up a VPS through Vultr, getting your bot up and running, and then testing out that connection to make sure your bot is working as intended.
Getting Your Code Ready and Version Controlled Through GitHub
Before we can begin setting up your VPS Hosting, there’s one very important thing we can’t forget: Version Control.
I want to start off by saying this step is optional but highly recommended.
What is Version Control?
Version Control in software is a way to keep track of every single change made to bits of code throughout the entire lifecycle of that code, from start to finish.
To put it simply, every single time you change something in your code (whether you add some functionality, fix/remove some bugs, etc.), you then “check-in” or “commit” your changes.
Benefits of Version Controlled Code
Once your changes are “checked in,” you’ll be able to go back and compare those changes to past versions, letting you clearly see what changed.
You’ll also be able to revert back to an old version if you accidentally break something.
This is great if you’re just starting out and want to have the freedom to experiment with your bot.
Taking note of all the reasons above, this is why we’re going to set up our Discord Bot Version Control system through GitHub first.
And if you’re wondering, “Why GitHub?” Two Reasons: It’s free, and it’s easy!
We’re not going to walk through a detailed setup right now, as it’s out of the scope of this article (we’re talking about bot hosting, after all).
But there are some great resources you can follow along with to get version control set up from scratch.
Git Learning Resources
The first place you should browse around is the GitHub Guides help page. This has everything from quick lessons on how Git works all the way to more advanced Git topics.
If you want to go “straight to the source,” as they say, then I’d recommend starting with this guide on GitHub flow.
Once you’ve gone through that one and understand the basics, GitHub’s Hello World guide is a great starting point for going through the whole version control process from start to finish with some sample files.
Once you’ve placed all of your code under version control, you can rest easy knowing all of your changes are tracked and preserved!
Now let’s move on to the fun stuff — actually hosting your Discord bot through a third-party server.
Vultr VPS
And it begins… This is the part of the guide where we finally start setting up and configuring your Virtual Private Server to run your Discord bot 24/7.
We will be using Vultr as our VPS of choice since they have an awesome deal for WriteBots readers: Get $100 instantly to spend on hosting if you sign up with a brand new account! You get the $100 for several weeks, which is enough to test a lot of different bots.
We’ll be showing all of this with an example ping-pong bot made in JavaScript / Node.js, but it can easily be modified to fit any programming language on any platform.
Suggested Reading: If you’re interested in coding/creating a Discord bot from scratch, take a peek at our detailed guide on how to make a Discord bot. We cover every aspect from start to finish, letting you create your next bot in confidence.
Your first step is to create an account on Vultr.
Once you have your account set up and you’re all logged in, we’ll begin setting up our bot step by step in the next section.
Step by Step Setup
You’ve created your account and you’ve logged into Vultr. You should be at the primary home screen that looks something like this:
See that blue circle with the “+” inside? That’s what we’ll click next to deploy our new VPS.
You can select either “Cloud Compute” ($2.50/mo lowest tier) or “High Frequency” ($6/mo lowest tier, but faster) and then choose a location that’s closest to the majority of your audience.
Note that some locations have more options for hosting types than others, such as the New York (NJ) location which offers more monthly hosting options.
If you don’t know what location you should choose, picking any of the US locations is always a safe bet.
Next, you’ll have to choose your “Server Type” and “Server Size”.
For Server Type, I’d recommend going with 64-bit Ubuntu 21.10. It’s stable and has a lot of documentation around it on the web. Ubuntu is an easier Linux to work with for beginners, which also makes it a great choice.
For Server Size, I recommend choosing an option between $3.50/mo – $5/mo to start. I can hear you saying it already, “But why not the $2.50/mo option? It’s cheaper, isn’t it?” Well, the $2.50/mo option in Vultr only includes an IPV6 Address. It’s only the $3.50/mo and higher options that include an IPV4 address, which is needed to access your server using a “normal-looking” IP address (see below).
If this sounds “alien” to you, a quick explanation is how IPV4 vs. IPV6 addresses look:
Here’s an IPV4 IP Address: 127.0.0.1
Here’s an IPV6 IP Address: 3FFE:F200:0294:AB0D:0394:4567:8911:ABDE
You’ll be using this “IP Address” to connect to your server and upload your bot’s files, etc. You don’t want to be typing that IPV6 address each time, do you? Having an IPV4 address is much cleaner.
Of course, if you don’t mind it and are willing to research a bit, you can choose the $2.50/mo option with an IPV6 address. This is entirely up to you — but I’d recommend IPV4, or the $3.50/mo and up options, for beginners.
For the next section, you can skip past “Additional Features” (unless you want to add Auto Backups and DDoS Protection), “Startup Script”, and “SSH Keys” for now.
The one piece you’ll want to fill out is the “Server Hostname & Label” section. This is where you name your server.
Once you’ve given your server a name and are satisfied with your settings, you can click the “Deploy Now” button!
You’ll see your new VPS server appear on the “Products” page in Vultr, and you’ll see a spinning orange indicator showing that it’s currently deploying/installing.
It can take up to ~5 minutes for your server to be fully deployed.
Once the indicator stops spinning, you’ll see that your server is “Running” and ready to go!
You should also be able to see the IP Address of your server next to its name.
Congratulations! You’ve successfully set up your first VPS.
We just have one little problem… it’s empty and there’s nothing currently running.
In the next section, we’ll talk about how to connect to your VPS, load all of your bot files into it, and get your bot up and running on your Discord server.
Getting Your Discord Bot Running 24/7, 365
You’ve “deployed” your empty VPS, and it’s sitting there waiting for your next command… what should you do next?
Well, here’s what we’re going to do: Load up all your bot files and start up your Discord bot! We’ll walk through doing this step-by-step in the next few sections of this bot hosting guide.
Logging Into Your VPS Server
But first, we’re going to want to take a look at our VPS in more detail. Click the name of your server on the Vultr “Products” page to dig deeper:
Once inside, you’ll see something like this:
You may notice that orange message lingering at the top, saying that it might take a few minutes to boot up and activate your server. You can ignore this message after you give your server about 5 minutes to boot up.
You can also see your server administrator, also known as root, “username” and “password” (click the little eye to show your password, and the paper icon to copy the password).
This is what you’ll use to log in to your server and have full control over its configuration.
Logging In Through Secure Shell (SSH) on Windows, Mac, and Linux
The best way to login into your server and start sending commands is through the Secure Shell Protocol (SSH). Whether you’re using Windows (10+), Mac, or Linux, each of these operating systems will allow you to connect to your server through SSH.
We’re going to walk through the process on Windows, Mac, and Linux so that you can connect to your server and start setting up your Discord bot.
Windows SSH Connection to VPS
For Windows 10 and up, SSH is included inside of Command Prompt, making it very convenient to connect to your server.
In the examples below, I’ll be using Windows 10 to connect to my newly created Vultr VPS.
- Open up Command Prompt on your machine
- Once the command prompt is opened, type the SSH command, substituting the “xx.xx.xx.xx” for your server IP found on your Vultr control panel:
ssh root@xx.xx.xx.xx
- If you get a message saying, “The authenticity of the host can’t be established”, this is okay. Type “yes” into the command prompt and hit enter.
- Copy your password from Vultr and paste it into the Command Prompt window. Note that for security purposes, the characters of your password will not show up in the black console window as you’re typing them, or if you copy/paste them. This is normal. Hit enter to submit your password and log in.
- Once you’ve logged in, you’ll see the terminal window become: “root@your-server-name”. Congratulations, this means you’ve successfully logged into your server!
- Now that you’re logged in, you can move on to the “Learning Three Easy Linux Commands” section below.
Mac SSH Connection to VPS
If you’re on a Mac, you can easily connect to your VPS through Secure Shell (SSH) by using your terminal. The following steps will show you exactly how it’s done.
- Open your Mac terminal.
- Referencing the image below, type the SSH command following the format below, and replace xx.xx.xx.xx with your VPS IP:
ssh root@xx.xx.xx.xx
- On the “Authenticity of this host can’t be established” message, simply type “yes” in the terminal and press enter.
- Copy and paste the password of your VPS from the Vultr control panel into your terminal. You can also manually type the password if you choose.
- Success! You should be logged in to your server’s root home folder.
Linux SSH Connection to VPS
To connect to your VPS on Linux through Secure Shell (SSH), all you need to do is follow a few simple steps.
- Open your terminal.
- Type the SSH command, replacing xx.xx.xx.xx with the IP address of your VPS server (found on the Vultr control panel).
ssh root@xx.xx.xx.xx
- If you get a message saying “The authenticity of the host can’t be established”, type “yes” and hit enter.
- Copy and paste your password from your VPS information page on Vultr
- You should be successfully logged in and ready to configure your Discord bot!
Once you’ve logged in, you’ll automatically find yourself in the “home” directory, which is indicated by the tilde “~”.
Now it’s time to set up your directory, get node.js and npm setup, and then load all of your bot’s files.
Learning Three Easy Linux Commands
Before we get into the details, you’re going to learn a few very easy-to-remember Linux commands.
Linux Command mkdir: Make a Directory
The first command is to make a folder or a “directory”. The command is short for “Make Directory”, and is spelled out like so: mkdir.
Here’s how you would use this command in action:
mkdir my-special-folder
Based on where you currently are in the console window, this command will create a folder and name it “my-special-folder”. Easy-peasy.
Linux Command ls: List All Files In the Current Directory
The next command we’re going to learn is used to list all of the files in the current directory you’re in.
Here’s how you would use it:
ls
You would type two characters, “ls”, and what you would see in your console is a list of files currently in that folder. It’s a simple command.
Linux Command cd: Go to a Directory of Choice
The final command you’re going to learn is how to “jump” into another directory. Since all we’re doing is typing and not actually clicking to jump from folder to folder, you’ll have to use the “Change Directory” command, which in shorthand turns out to be: cd.
Here’s how you would use it to jump from the current directory to a subfolder called “test”:
cd my-special-subfolder
And an example: (## are comments)
## listing all of the contents of our current folder
root@discord-bot-vps:~# ls
test
## changing directory to the ‘test’ folder
root@discord-bot-vps:~# cd test
## see the path change? We are inside the ‘test’ folder!
root@discord-bot-vps:~/test#
And that’s all there is to the “change directory” command.
Putting These Commands Together and Setting Up Your Project
So, before we even get started, let’s type “ls” in the window. Since we don’t currently have any files in our home directory, you should get — nothing! There’s a chance you’ll have a “snap” folder, but this can be ignored.
Now, if we create a directory named “ping-pong-bot” and then type “ls” again, we should see that directory be created on our server. Let’s give it a shot.
And there we have it… It worked. We created a folder (directory) called “ping-pong-bot”, and then saw it appear once we listed everything in our current directory.
All that’s left for us to do now is use the “Change Directory” command to go inside the ping-pong-bot folder:
And there we have it, we’re in the /ping-pong-bot/ directory!
Installing Node.js and Node Package Manager
Next, we’re going to install node.js on our server.
This can be done with a few quick Ubuntu commands (type each line one at a time):
sudo apt-get install nodejs
Once you type that command you’ll see it read the package and ask you if you want to install it.
You’ll want to type “y” for yes, and the installation will continue. It may take a few minutes to fully install, so be patient at this stage.
Optional Step: If you get a “Kernel outdated” message, and a pink screen like shown below, click “Enter” on the first screen, and then hit “Tab” to jump to the <Ok> button. Once <Ok> is selected in red, click “Enter” again to restart the recommended services on your VPS.
Once you’re back in the subfolder you created, node.js has been installed:
Now we’ll want to do the same thing with NPM, which is “Node Package Manager”
Type this command to install it:
sudo apt-get install npm
You’ll have to type “y” again for yes to continue installation, just like when you installed node.js in the previous step.
Once you’ve installed node.js and npm, time to check the installation.
To do that, we can use two commands to check their versions:
node -v
npm -v
We’re getting version numbers for node and npm, but these are out of date!
The next section will guide you through updating these versions.
Updating NodeJS and NPM
In order for our Discord bot to work correctly, we have to have a NodeJS version of 16.x and above. By running a few simple commands, we can update our Node and Npm installations:
sudo npm install -g n
sudo n stable
hash -r
You should see higher version numbers, and your node -v command should return a version 16 and above.
Setting Up Our Node.js Project
Now we want to “initialize” our project using the Node Package Manager.
This is done through one simple command, and it’ll bring up a “wizard” where you follow along with the steps and type in your responses.
npm init
Important: Before you type the “npm init” command, make sure you’re still in the right folder!
Node will be creating all of your project’s files in the folder you are currently in, so double-check the path to make sure you’re still in the right one.
Here’s what the setup process for “npm init” should look like.
I just kept hitting “enter” to go with default values, and the only thing I changed was the “Description” field.
Once you type “yes” at the end, your node project will have been created.
Installing the Discord.js Library to Make Life Simple
To make life super easy we’re going to be using the “discord.js” library in our ping pong bot.
A library is a set of pre-written code that interfaces with the Discord API; this is what lets us send/receive commands from Discord to/from our server.
Additional Reading: If you want to learn more about setting up discord.js and libraries, check out this guide on how to make a Discord bot. You can also jump straight to the libraries part of the guide, or directly to the JavaScript bot creation portion.
In any case, installing the “discord.js” library is very simple, involving just one Linux command.
In your Vultr server console (or your own SSH client; see the SSH client section of this guide), while in your bot’s directory, type the following command:
npm install discord.js --save
You’ll see different colored text while the installation process finishes.
By adding –save to the end of our “npm install” command we made sure that our package.json file was updated to include discord.js as a dependency.
We’ll verify our installation in the next section.
Verifying Our Installation
It’s time to make sure everything is installed correctly.
The first thing you’ll want to do is type “ls” to list all of the files in this directory. You should see the new “package.json” file that was created when we ran “npm init” and also a new folder titled “node_modules”:
The node_modules folder contains our new “discord.js” dependency that we just installed.
We also want to double-check the “package.json” file to make sure “discord.js” was added as a dependency.
We can do this by running the “cat” command:
cat package.json
After this command has been executed, we should see its contents with the “discord.js” dependency included successfully:
Success! Everything we need has been installed.
All that’s left for us to do is upload our bot’s files to the server and get our bot up and running! We’ll do this in the next section step by step.
Uploading Your Bot’s Files
Whew! The tough part of our setup is all finished!
From here on out, all that’s left for us to do is to (1) Upload your bot’s files and (2) Launch your Discord bot!
Remember how in the last section, we ran “npm-init” and used the default “Entry Point” or “main” filename: index.js?
You can either modify your node package.json file and change the entry point file name to whatever you’d like, or you can leave it at its default “index.js”.
Note: If you want to modify your “package.json” file straight from the command line, you can do it with nano! Nano is a Linux text editor that lets you modify files on the fly.
To learn how to use nano, check out this guide to nano. But before you read that guide, this is very important: Whenever they write “^X” or “^K”, anything with a carat (^) before a letter, the carat is the CTRL key on your keyboard!
This means that “^X” is CTRL+X on your keyboard. I just wanted to clear this up, as it’s very commonplace to get stuck with the nano text editor.
Important: To use nano, you’ll need your own SSH client. Take a look at the SSH section of this guide above (Windows, Mac, Linux) for more details on setting this up.
If you look inside of your package.json file (by typing the command: “cat package.json”), you’ll see what your current “main” is set to.
Anyways, let’s actually upload our bot’s main file containing all of our code.
Here’s what our “index.js” will contain:
const { Client, Intents } = require('discord.js');
const intentList = new Intents();
intentList.add(Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES);
const client = new Client({ intents: intentList });
client.once('ready', () => {
console.log('Ping Pong Bot Loaded!');
});
client.on('message', message => {
if (message.content === 'Ping') {
message.channel.send('Pong!');
}
});
client.login('your-bot-token-goes-here');
This is a simple bot that uses the “discord.js” library to write a message as soon as the bot is all started up and loaded saying, “Ping Pong Bot Loaded!”
As soon as someone types a message that says “Ping”, our bot will reply, “Pong!” Super simple.
IMPORTANT – DO NOT SKIP: Don’t forget to create your bot application and get a token. If you haven’t done this yet, check out this guide on how to get a discord bot token. It walks you through setting up a “bot app” on Discord and revealing your token.
Once you have your token, be sure to replace the “your-bot-token-goes-here” inside of index.js with your token. This is critical, and your bot won’t connect to Discord otherwise.
To make uploading our files as easy as possible, we’re going to connect to our server through an application called “Filezilla”.
Note: You can download FileZilla directly from this link.
Once you’ve downloaded FileZilla, open up the client! You should see a screen similar to this (except your color scheme may be different from mine):
You’ll want to click that icon in the upper left-hand corner in order to set up a connection to your server.
And then, you’ll want to click the “New Site” button.
This is where you’ll have to go back to Vultr and get your IP Address, Username, and Password from your “Server Information” Page:
You’ll need this information for the next few steps in order to connect to your server.
What you want to do next is to select the following settings:
- Protocol: SFTP – SSH File Transfer Protocol
- Port: LEAVE EMPTY
- Logon Type: Normal
- User: root (from Vultr)
- Password: (from Vultr)
Then click on the “Connect” button!
Since this is your first time connecting to your server, and because we’re connecting securely through the “SSH File Transfer Protocol,” you’ll have this message come up:
Click the “Always trust this host” checkbox to acknowledge the message and hide this prompt whenever you connect in the future.
You should then connect and see all of your server’s files in the “Remote Site” right-hand side of FileZilla!
We can see our ping-pong-bot folder listed, and can now click through and browse around on our server just like we would on our computer.
The first thing you want to do is browse into your bot folder (in my case, I clicked into ‘ping-pong-bot’).
Now, I’m going to go on my computer, create a text file called “index.js”, and paste the bot code from the last section.
I’ll then save this file and drag it into the ping-pot-bot folder on FileZilla to upload it.
… so I did just that. I created the “index.js” file on my computer and saved it. Don’t forget to include your token!
Then I dragged the file into the ‘ping-pong-bot’ folder on FileZilla, and saw it uploaded successfully:
To double-check this, we can go into our Vultr server console (or SSH client) and type “ls” to list all files:
Yep, “index.js” is definitely there!
And as a final sanity check, we can even do “cat index.js” to see its contents:
Yep.. that definitely looks like our ping pong bot’s code, alright!
Important Step: If you haven’t already generated your Discord bot token and added it to your bot’s index.js file on your Discord server, follow along with the discord bot token guide to get all of this setup.
The final step in this process is to get our bot up and running and then test it out on Discord!
Getting your Discord bot up and running
We are on the final few steps before we can actually see our bot in action on Discord.
Continuing the Process: Installing a Process Manager
The next thing we need to do is install a process manager. Why you might ask?
Well, a reliable process manager is going to let us run multiple bots on our VPS (if we so choose), and perform all of the memory management required to keep every task operating at its peak.
PM2 (Production Process Manager for Node.js) is an awesome choice that’s very widely used with Node.js projects.
Check out PM2’s website for more details on its capabilities as well as installation instructions.
Installing PM2 is super simple and requires running this command on your server’s command line (or SSH shell).
Make sure you “cd” (change directory) to your main bot’s project folder before running this command:
npm install pm2 -g
You should see the installer doing its thing:
… and as soon as the progress bar stops scrolling, PM2 should have been installed successfully!
To test if PM2 was installed successfully, we can list all currently running processes (which should be none, since we haven’t started any!):
pm2 list
Yep, just as expected, no running processes. Time to fire up our bot!
We can do this through another simple command using pm2:
pm2 start index.js
Note: You should change “index.js” to whatever your bot’s main code filename is.
Note: pm2 start will fail if you forgot to “cd” into your “ping-pong-bot” directory. Double-check this.
After you run the “pm2 start” command, should see a message from PM2 saying that it started an instance of your bot, and your bot should now be successfully running!
Success! We can see App Name shows “index”, and or Status shows as “online”!
If you ever want to stop your bot (or any process you start with PM2), all you have to do is run the following command:
pm2 stop index.js
And if you ever want to list all your currently running processes, you can run a simple “pm2 list” command on your server.
Troubleshooting: If you run “pm2 list” and your bot shows as “errored” in red text (see screenshot below), this might be because you didn’t add your Discord bot token to index.js. I can’t stress enough how important it is that you did this.
To see exactly what your Discord bot’s error message is, type the command:
cat ~/.pm2/logs/index-error.log
This will open up the PM2 error log, letting you see the Discord.js error messages that prevented your bot from running. Copy and pasting these messages into a search engine is the quickest way to get a sense of direction.
If your bot is up and running, running pm2 list should show as green and “online”:
Congratulations! You have just hosted your first bot on a Virtual Private Server, all on your own! Give yourself a pat on the back — getting this far is a big deal!
You now know how to host one bot and even multiple bots on a single VPS!
For multiple bots, you would do the same exact thing we did here and just start up another process on PM2. Easy peasy.
In the next section, we’ll see our bot live on our Discord server and watch it actually running in the wild… let’s do it.
Testing Our Bot on a Live Discord Server
The last step is testing our bot out “in the wild” on an actual Discord server!
Important: In case you haven’t generated a token yet and added your bot to Discord. Read through our guide on how to get a Discord bot token for step-by-step instructions on adding your bot. Make sure your token is inside “index.js” or you may see errors.
I have already added “ping-pong-bot” to my Discord server, and since our process is actively running in PM2, we can see this bot as ONLINE!
Success!
All that’s left for me to do is test out my code by typing “Ping”. If all works as it should, my bot should say “Pong!” in the chat.
Let’s give it a try…
It works. Our bot is officially up, running, and online!
Shutting Off Your Discord Bot
As a final step, you might want to stop or restart your bot if you’ve made changes to your code, or just want to start up another bot.
As I mentioned earlier, PM2 lets you run multiple bots (as many as your server permits). Since node.js is rather light, on Vultr’s $5.00/mo plan you should be able to run several bots with at least 100+ connections.
This is a rough estimate, of course, and depends on how much memory your code actually uses (and how big your bot is). The point here is, you should be able to easily host multiple Discord bots without issue!
And if you ever wanted to upgrade, you could easily “clone” your Vultr VPS over to a larger more powerful instance.
Anyways, lets first list the processes we have running in PM2 with the “list” command:
And then we can stop our app by typing “pm2 stop <app name>”:
To verify, let’s go on Discord and check if our bot is offline:
Crickets. Our bot is definitely offline.
Final Thoughts on VPS Discord Bot Hosting
And this concludes our Discord Bot Hosting guide.
You should now know everything you need to know to get your JavaScript / Node.js bot up and running on your own, personal Virtual Private Server.
If you want to host your bot in a similar language such as Python, all you need to do is install Python on your Vultr, and… you’re good to go! (you just won’t be able to use PM2)
The same goes for any programming language or code you want to run.
Even if you wanted to run a “Discord Bot Maker” instance, you could do so by installing Windows on your VPS and starting it up from there (just remember that Windows VPS servers are more expensive monthly than Linux, which is why we tend to go with a popular Linux distro like Ubuntu).
Either way, you’ve achieved what most won’t — hosted your own Discord bot on your own VPS.
For that, I want to say congratulations and good luck on your botting journey!
Alternative Discord Bot Hosting Options
Hosting your Discord bot on your own VPS is the best option, but not the only option.
If setting up a VPS just isn’t for you, or if you simply like exploring alternative hosting options, then this is the section for you.
We’re going to cover hosting your own Discord bot on the Heroku platform, we’ll talk about Amazon AWS, and then to conclude we’ll go through an example of hosting your very own Discord bot on a Raspberry Pi.
Let’s get moving!
Heroku
Heroku is a cloud application platform that lets you deploy your apps in the cloud and get them running nonstop, 24/7.
It works for hosting Node.js, Ruby, Java, PHP, Python, and Go code.
Heroku is free if you just want to experiment with your bot, but paid if you want your server to be up and running nonstop. The free version of Heroku lets you deploy an app (they call them “dynos”), but it’ll go to sleep after every 30 minutes of inactivity.
As of the time this article was written, the cheapest paid plan for Heroku came in at $7/mo.
This is considerably more than hosting a bot on your own VPS where you can:
(1) Get hosting for as low as $3.50/mo or $5.00/mo
(2) Get a free $100 to put towards hosting costs just for signing up!
Heroku is especially handy if you have most of your bot’s code on GitHub since there’s an “automatic deploy” option that pulls your code from GitHub and copies it over to your Heroku Dyno.
Important Note: If you put your code on GitHub and use “automatic deploy”, make sure your repository is set to private because it’ll have to include your Discord bot token! Never make your repository public with your token visible.
In either case, Heroku can be a good hosting option depending on what you want to get out of it. Let’s go through the process of setting it up.
Setup Guide: Hosting Your Discord Bot on Heroku
For our example setup, we will be powering up a Discord bot written in JavaScript / Node.js on Heroku. This bot will also be using the Discord.js library to interface with the Discord API.
Here is the Discord.js on Heroku guide we’ll be following along with.
The guide starts by going over some Heroku basics and then introducing the files you need in your project for hosting on Heroku (package.json, Procfile, .gitignore, and index.js).
You’ll then install all of the prerequisites you need to get your bot up and running, including Node.js, Git, GitHub, and the Heroku CLI (command-line interface).
You’ll then run the “npm init” command (just like we did in our VPS hosting portion of this guide, up above) to create your package.json file, and then create a Procfile.
Heroku uses the “Procfile” or “Process File” to determine what processes are started on each of your “Dynos.” For clarity, a “Dyno” is your virtual Heroku Container or “miniature server” in a sense.
Once you’ve done that you’ll get your code transferred to your Heroku Dyno, and then deploy your app!
That’s all there is to it. You have successfully deployed your JavaScript / Node.js bot on Heroku!
Note: If you want more reliable hosting and complete ownership of your Discord bot’s server, I recommend following the first part of this guide and setting up your own VPS.
AWS (Amazon Web Services)
AWS, or “Amazon Web Services”, has been taking the world by storm. In fact, there are hundreds of Fortune 500 companies using AWS to power their internet infrastructures.
This makes AWS sound like a pretty reliable bet, doesn’t it?
For clarity, AWS is the “overarching” platform containing all of Amazon’s services. For hosting our Discord bot specifically, we’ll be using Amazon EC2 — Short for ECC or “Elastic Compute Cloud”.
This is where we’ll be able to deploy our own mini-server through EC2, and then get it up and running with our Discord bot.
Note: Even though Amazon EC2 has great value in your first year, we recommend setting up your own VPS Discord bot hosting for a slightly easier setup (see the first part of this guide for details). EC2 offers 750 free hours for the first year on their “EC2 Micro Instances” — after that, you’ll be paying for uptime.
For our AWS / EC2 hosting example, we’re going to be creating an EC2 Cloud Instance and deploying a JavaScript / Node.js bot.
Here is the Node.js bot deployment on EC2 guide we’ll be following along with.
That guide is super in-depth and covers everything you’ll need to know for deployment to EC2 — perfect for our purposes!
You’ll start by creating a server instance through EC2 (running on Ubuntu, to be exact), and then launching that instance.
Once it’s launched you’ll set up SSH (Secure Shell) access to your AWS server, and then upload your files through SFTP.
What you’ll be doing here is very similar to the process we took in the first part of this guide to set up VPS bot hosting on Vultr. One of the big differences I noticed is using the “Forever” Node module for consistent 24/7 uptime rather than using “PM2” as we did in our guide.
Once you’ve gotten your EC2 instance configured with all of your bot files loaded, you’ll launch your bot!
This method does require some light Linux knowledge and commands, but it’s not that difficult to follow along from start to finish.
Raspberry Pi
A Raspberry Pi is a “miniature computer” — and that’s right, you can host your own Discord bot from your own R-Pi and have it up and running 24/7 (as long as you don’t lose power!)
As of the time this guide was written, the latest version of the R-Pi available on the market was 4.0, but you can still find older Raspberry Pi versions for sale on the web.
Hosting our Discord bot on a Raspberry Pi is going to be very similar to the process we took to host on a VPS since we’ll still be using JavaScript / Node.js and working on a Linux platform.
Note: Your Raspberry Pi can be a very reliable Discord bot host, but it only goes so far as you’re able to keep it up and running. If you have a bot used by lots of different servers, your R-Pi may struggle to keep up with memory/resources. This is why we still recommend hosting your own Discord bot on a VPS.
Here are the guides you can follow along for Raspberry Pi Hosting:
If you want to host a JavaScript / Node.js bot, install Linux on your Raspberry Pi and follow our VPS instructions exactly as they’re written – easy as that!
If you want to host a Python bot with Discord.py, follow along with this Python Raspberry Pi hosting guide. Difficulty: Intermediate
No matter which guide you choose, both will get you to a working Raspberry Pi server for your Discord bot.
I mentioned earlier that the process of an R-Pi is going to be very similar to how we hosted our bot on a VPS.
This is because it’ll start out with you connecting to your Raspberry Pi, then installing either Node.js or Python.
Once you’ve installed your code runtime environment, you’ll move on to loading your bot files into the Raspberry Pi.
And finally, once all of your bot’s files are loaded, you’ll be able to start them up and get your bot running! The Node.js guide uses PM2 for process management (just like we did in our VPS hosting guide above), and the Python guide uses the Python runtime environment to launch your Discord bot.
Once you’ve launched your bot, make sure to periodically check in on your Raspberry Pi to ensure things are running smoothly.
And when your bot grows and starts being used by more servers (and more users simultaneously), you can always transfer over to VPS hosting to handle more bandwidth.
Free Discord Bot Hosting
Most of the Discord bot hosting options we’ve covered up until now have been paid or premium solutions.
These are, of course, the best options for reliable hosting — but what if you wanted to do it absolutely free?
Well, you’re in luck because there are a few ways you can host your Discord bot for free without any Virtual Private Servers or Cloud Instances.
The first method we’ll talk about is “Glitch,” and the second method we’ll cover is simple “Self-Hosting” from your own computer.
Remember: Both of these hosting methods won’t be as reliable as an official, third-party VPS host, but we can get some fairly decent reliability by implementing a few “unique tricks.” Stay tuned for those.
WriteBots VPS Offer: Get a free $100 to spend on hosting your own Discord Bot when you sign up today!
Self-Hosting
This is the ultimate free hosting option — running your Discord bot from your very own computer.
Of course, this will only work well if you (1) Have your computer up and running 24/7 without going into sleep mode and (2) Have a fast internet connection to handle API requests to your Discord bot.
Fortunately, hosting on your own computer is extremely simple.
All you have to do is install your code runtime environment (whether that’s Node.js, Python, Java, etc.), and then run your bot… that’s it.
Once your bot is running it’ll connect to and communicate with the Discord API, and run as it normally should.
If you’re just getting started with Discord bots, this is a great way to test your bot and make sure it’s working correctly.
If you’re looking for more permanent solutions, then you should consider getting your own private VPS server to host your bot and keep it up 24/7, 365.
This is the simplest way to host a Discord bot and one that you should definitely have tried first when testing your bot or just starting out.
Hosting Specific Types of Discord Bots
So far, we’ve talked about hosting Discord bots at a very “general” level. We just assumed that your bot is a “black box” with some code, and your goal is to get it up and running on a reliable server.
This is all well and good until we get to some more specific examples of bots that need to be hosted.
In this section, we’re going to go over the process of hosting a Discord Music Bot, Discord.js Bot, and even bots made with Discord Bot Maker.
Discord.js Hosting
Hosting a bot made with Discord.js is one of the most common methods on the web today.
This involves having Node.js up and running and then installing the Discord.js module via. NPM (the Node Package Manager).
We cover Discord.js hosting in extreme detail in the first part of this guide.
If you follow along with the beginning of this hosting guide from start to finish, you’ll pick a reliable VPS host, get your code version controlled, set up your VPS server, and then load up your Node.js / Discord.js code.
By the end, you’ll have a fully configured VPS server running your Discord bot all day, every day.
And again, since we already covered this in detail in the first part of this guide, we’re going to point you over there to get your Discord.js bot hosted and ready!
Music Bot Hosting
Hosting a music bot is, as you would imagine, more difficult than any regular Discord bot.
Since music bots actively buffer and stream data, they take up a lot more bandwidth and a lot more memory than your typical Discord chatbot.
For this reason alone, we’d recommend going with a VPS hosting solution to bring up your music bot to its maximum potential.
Follow along with our VPS Bot Hosting Guide for more details on how to get your bot up and running with third-party hosting.
The process should be exactly the same, except for the additional audio modules/codecs your bot requires. Unfortunately, this isn’t a “one size fits all” with every music bot using different modules and/or codecs.
One of the most popular codecs is FFmpeg, so your Discord Music Bot may be using it as a dependency.
Either way, your next steps are two-fold: (1) Find out which codecs/modules your music bot uses (2) Install those modules on your VPS in addition to the rest of the modules you need to run your bot.
Once you have all of your modules/codecs installed, you’ll be able to start up your bot and then test it out on your Discord server.
Happy listening!
Discord Bot Maker (DBM) Hosting
Ah, Discord Bot Maker.
I’m personally not a fan of the software (it’s too limited in my opinion, compared to what you can create on your own), but there are those of you out there who love it and want to host your own bot with it.
I can respect that.
This part of the guide walks through everything you need to know about hosting a bot made with Discord Bot Maker. It should be very simple to follow.
To host your Discord Bot Maker creation, you have one of two options:
Option 1: Self-Host your Discord bot on your own personal computer
Option 2: Get a third-party VPS with Windows on it and then install/run DBM.
DBM Hosting Deal for a Windows VPS: Since you’re a WriteBots reader, there’s an awesome deal where you can get $100 free to put towards VPS hosting just for signing up! Take advantage of this before it disappears, and don’t forget to choose the “Windows” server option.
If you’re going with “self-hosting,” all you need to do to host your DBM bot is just… to start up Discord Bot Maker and run your bot!
And if you decide to go with a Windows VPS Host, you’ll have to connect remotely through RDP (Remote Desktop Connection) and then install DBM that way.
Nice and easy.
Once you’ve done that, you’ll have your very own Discord bot created in DBM and hosted on your own server. Great work!
The Impact of Reliable Hosting on Your Discord Server
Having reliable hosting for your Discord bot is crucial to your user experience.
Imagine if one of your frequent Discord Server users joined a channel with your bot, tried to use your bot, and kept getting the disconnected or “offline” message every single time.
I don’t know about you, but I’d be upset/annoyed if it happened consistently.
Having reliable bots on your server that are up and running no matter what time of day it is — that’s how you grow your server to new levels.
Don’t make a bad impression on your new and seasoned Discord users.
Get reliable hosting for your bots.
Final Thoughts
We’ve covered a lot here.
This guide should’ve taught you everything from hosting your JavaScript/Node.js bot through a Virtual Private Server (VPS), all the way to specific types of hosting for bots made on Discord Bot Maker or the Raspberry Pi.
No matter your goal with hosting your Discord bot, I sincerely hope this guide gave you all of the answers you needed.
Leave a comment below and let me know if there’s anything you’re stuck with, have a suggestion on, or think is missing from this guide.
I wish you the best of luck with your Discord bot hosting endeavors!