> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.sparkedhost.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to run a Discord.py bot on a VPS

### How to run a Discord.py bot on a VPS

1. Connect to your VPS via SSH

2. Run the following commands: 

* `apt install python3-pip` 
* `apt install npm -y` 
* `npm i pm2 -g`

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/01-installing-packages_1ooqdot.png)

3. After installing the packages, run the following commands:

* `pm2 flush`
* `pm2 install pm2-logrotate`
* `pm2 set pm2-logrotate:max_size 10M`
* `pm2 set pm2-logrotate:compress true`
* `pm2 set pm2-logrotate:rotateInterval '0 */1 * * *' `

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/02-modify-pm2_6md456.png)

Running these commands will make it so that the pm2 logs stop creating very large log files in the long term.

### How to start running Discord.PY Bots using PM2

1. Connect to your VPS via SFTP. In this case, we will be using FileZilla. Upload the contents of your bot to your VPS

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/03-filezilla-transfer_28u5s2.png)

2. Then using SSH, use the `ls` command to see the content of the folders that you are currently on, and use the `cd <Folder/Directory>` command to navigate through the folders. Also, to go up a folder, run the command `cd ../`.

For Example: If you want to get from the “root” folder to “Discord Bots > DjsBot”, just run the command `cd ‘Discord Bots’/DjsBot`.

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/04-navigate_1519oqr.png)

3. Now to start the bot, run the command `pm2 start <Startup Bot File> --interpreter=python3` or `pm2 start <Startup Bot File> --name=<Name of the Process> --interpreter=python3` to give the process a name.

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/05-start-bot_1xcb4jj.png)

### How to restart the bot using PM2

1. To restart the bot, you need to get the bot’s process ID or the process name that you’ve set when starting the bot.

|| Note: You can get the process ID by doing `pm2 ls` and find the id corresponding to the process name

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/06-pm2-list_1b3xh67.png)

2. Run the command `pm2 restart <Process ID or Name>` and your bot will restart.

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/07-pm2-restart_1t5avuz.png)

### How to stop the bot using PM2

1. To stop the bot, you need to get the bot’s process ID or the process name that you’ve set when starting the bot.

|| Note: You can get the process ID by doing `pm2 ls` and find the id corresponding to the process name

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/06-pm2-list_1b3xh67.png)

2. Run the command `pm2 stop <Process ID or Name>` and your bot will restart.

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/08-pm2-stop_1g7jao0.png)

### How to view the logs of the bot using PM2

1. To view the logs of the bot, you need to get the bot’s process ID or the process name that you’ve set when starting the bot.

|| Note: You can get the process ID by doing `pm2 ls` and find the id corresponding to the process name

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/06-pm2-list_1b3xh67.png)

2.Run the command `pm2 logs <Process ID or Name>` or `pm2 logs <Process ID or Name> --lines=<Line Amount>` and pm2 will show the bot’s console logs.

![](https://storage.crisp.chat/users/helpdesk/website/a79efd0b48a91800/09-pm2-logs_1f0nd5a.png)

---

If you require any further assistance, please create a ticket [here](https://billing.sparkedhost.com/submitticket.php).

---

Created By: Alecz R.