How to host a Discord.js bot 24/7 for free
So, you’ve got a super cool Discord Bot ready to pop off around Discord, but no where to host it? In this post, I will show you the best method of hosting your Discord.js Bot in under 15 minutes! No, really!
Configuring your Discord.js Bot
Once your service is activated, go ahead and check your emails for the activation notice. Towards the bottom of the email you should see your username and password to your bespoke Discord.js Hosting Control Panel, go ahead and login!
Once logged in, you should be taken to your dashboards home page. From here, you have options to create scheduled backup tasks, restore backups, upload files, change the node.js version, run NPM install and more!
But for now, go ahead and click on “File Manager” from the top navigation bar. The File Manager is user friendly, and can be used to download, restore, delete, move, edit and make any other modifications to your files quickly, and easily. Without the need to login to FTP.
This is the section we will use to upload your Discord.js Bot project. Simply drag and drop all of the files from your project into here but not the node_modules folder! The dashboard will automatically run NPM install on every server boot pulling configuration from your package.json file.
Once your files are in place, head on over to the “Startup” bar at the top of your screen and ensure the “Startup File” variable matches the name and extension of your main bot file you would typically run to start your Discord.js Bot.
That's it, it's that easy!
That’s the easiest and definitely the fastest way to get your Discord.js Bot online permanently. However, if you’re looking for a more hands-on solution, we also have you covered.
Bonus: Hosting a Discord.js bot on a VPS
To get started hosting on a private virtual server, head on over to this page and grab the hosting package of your choosing, note that any of our VPS hosting packages are fully capable of hosting large Discord.js Bots. For this node guide we will be using Ubuntu Server, so it may be worth using that as well!
Once purchased, and your package automatically deployed and activated (this should be instant), go ahead and check your emails for the activation notice, towards the bottom of the page you should find attached your VPS’s root password. It is highly recommended to change your password, so SSH into your server (if on Linux) using your IP address, username (root), and the password in your email.
Once you are logged in through SSH, run the following in your terminal session:
Awesome, your password is now securely set on your new server! Time for some configuration!
Installing Node.js (Ubuntu Server)
To install node.js on your Ubuntu Server, run the following commands:
This command will get all the updates and security releases for your server.
This will install all of the updates found from the last command!
In order to download node.js from the official node source, this dependency is required!
The above command will fetch the latest node.js versions ready for install.
Installation! To verify Node.js and NPM have successfully installed, run the following command:
Making a project directory and uploading your Discord.js bot ready for hosting
To create a directory / folder for your bot to be hosted from, run the following command. We will use `/discord/bots/example` for this guide, so you may feel free to change example to your projects name. Or, choose a different directory entirely, its completely up to your preference!
Once your folder has been created, its time to upload your files! To do this, we will be using SFTP, a file transfer protocol which utilises SSH (Secure Shell Access) for the transfer of files. To get started, download your FTP client of choice, I’ll be using Filezilla.
Once your logged into your FTP client using SSH (port 22), your username, ip address and password, change your directory by typing into the “remote site” to the one we just created with SSH. In this case, it will be `/discord/bots/example`.
Next step, upload your bot files! To do this, simply drag and drop all your project files excluding the node_modules folder, we will not be needing this.
Final steps, starting your bot
To start up your bot, head on over to your terminal / SSH session and “cd” into your project directory.
Once in your directory, simple run the following commands to start your Discord.js Bot!
Running this command will generate a new node_modules folder for your project using your package.json file
Congratulations, your Discord.js Bot project is now online permanently for the world to enjoy! If you found this post helpful, please let us know what you think of it in the comments section below. And while your down there, we would love to hear your cool Discord.js Project Ideas!