Let's assume that you have written a Discord bot. Even though you run this bot in the cmd command window on Windows, if you finally close the cmd command window, your bot becomes inactive and remains offline on Discord.
To ensure continuity, there are discord hostings on the internet and these companies constantly ensure that your discord bot remains active, but if you have a VDS server, you will not need these companies. The ping value of your Discord bot may vary depending on the features of your VDS server. We will only tell you how your Discord bot will always remain active for the VDS server you bought from scratch and what you can do to keep it active.
1. Required Programs;
Putty : https://www.putty.org/
We need to connect to our Linux server with Putty and install the software required for our bot to run.
WinSCP : https://winscp.net/eng/download.php
We need to upload our bot's files to our Linux server via SFTP with WinSCP.
2. Required Site;
Pm2 : https://pm2.io/
The control site of the module required for the continuous operation of our bot. Thanks to this site, our bot's CPU RAM etc. You can check its features on this site.
3. VDS ;
You can buy yourself an affordable VDS server from VDS provider companies and ensure that your bot runs continuously. My personal preference is @Teknosos; I use.
Setup
First of all, we need a Linux environment for our bot to run. For this, I will explain my operations on CentOS 7, which is my choice. You can easily set up your virtual server with a single click from your customer panel. With Teknosos you are always one step ahead.
1 stage
Let's assume that you have installed CentOS 7 on the VDS server you purchased from the hosting company. Now let's log in to the VDS server we set up with Putty.
After logging in, a black window will appear and ask us to log in. In the "login as:" section, let's enter the password information provided to us by the hosting company from which we provide the VDS server or the password we created ourselves, in the "root" password section. (It keeps the characters you write in the passwords confidential for security reasons.)
Stage 2
First of all, we need to keep our CentOS 7 version up to date in order for our system to be up to date. To do this, let's write the code I mentioned below into the Putty panel and wait for the system to update.
Code
$ sudo yum update
Stage 3
After updating our CenOS 7 version, let's install Node.js, which is required for our Discord bot to work.
Code
$ sudo yum install -y nodejs
This code will install the latest version that can be installed on the VDS server. Write the code below to check.
Code
node -v
Stage 4
Let's move on to the installation of the pm2 module, which is necessary for our Discord bot to run continuously. If you do not install and run this module, your bot will shut down after you close the Putty panel and will remain in offline mode until you open and run the panel again. The pm2 module must be installed globally or you will not be able to run the module.
Code
sudo npm i -g pm2
In the npm module, the shorthand for the "install" command is defined as "i".
Stage 5
We have installed it as shown in the add server section on the pm2 site, and it has given us a key such as "pm2 link xxxxxxxxxx xxxxxxxxx" to connect to our own panel. Thanks to this key, we can control our server without connecting with Putty via the pm2 site.
Stage 6
We have installed all the necessary modules, now we need to add the files of our Discord bot to the folder in centos via SFTP.
Let's connect to our VDS server with WinSCP
After completing the connection process, the only area that concerns us will be the root file. The files belonging to our Discord bot and the modules we will use for the Discord bot will be located in the root file.
Stage 7
Discord Modules can be installed by typing as follows.
Code
npm i discord.js
Stage 8
Let's come to the module that will keep our Discord bot always open. Assuming that everything is ready, we can run our discord bot with commands like "node bot.js & node server.js". We had installed the pm2 module globally to ensure its continuous operation. Now let's run the pm2 module.
Code
pm2 start bot.js
Assuming your bot's run command is "bot.js", your bot is now running.
-pm monitor
Code
pm2 monitor
pm2.io On-Site Monitor
You have examined the knowledge base in detail, but if you cannot find the information you need,
Create a Support Ticket