Come chat with us and we will get back to you as soon as possible!
Contact SupportHolyHosting
Holy Team

Adding bots to your Discord server allows you to automate tasks and add new features. Although you can use pre-made bots, creating and hosting your own gives you full control over its functionality.
In this article, we will explain how to host a Discord bot with HolyHosting's virtual private server (VPS) hosting plan.
Then, we will explain how to acquire a HolyHosting VPS hosting plan and set up the development environment for the bot. After that, we will cover how to upload and start the bot.
How to Create a Discord Bot
1. Create a Discord Bot Account
2. Configure Bot Permissions
3. Choose a Programming Language
4. Code the Bot
How to Host a Discord Bot
1. Get VPS Hosting
2. Set Up the VPS Environment
3. Upload the Discord Bot
4. Start the Bot
5. Monitor and Maintain the Bot's Performance
FAQ on How to Host a Discord Bot
1. What Is a Discord Bot?
2. How Do I Choose the Right VPS Hosting for My Discord Bot?
3. What Programming Language Should I Use to Build My Discord Bot?
4. Can I Run Multiple Discord Bots on the Same Server?
How to Create a Discord Bot
Hosting your own Discord bot tailored to your preferences requires it to be manually developed. The steps may differ depending on your bot's functionality and programming language, but the general procedure is similar.
1. Create a Discord Bot Account
To start creating a Discord bot, create an account on the Developer Portal. On this platform, you will create bots, manage their settings, and generate the authentication link to invite them to your Discord server.
To create a Discord account, go to the registration page. You will automatically log into the new Discord account if you open the Developer Portal. Then, follow these steps:
- In the sidebar, click on Applications.
- Select New Application in the right corner.
- Enter your bot's name and check the privacy policy checkbox. Click Create.
- Change the application icon. Enter the description and tags. Click
Save Changes to confirm.
- Copy the Application ID and save it to your computer. We will need it later to enable Developer Mode.
Then, set up your bot token, an authentication key that allows your application to communicate with the Discord bot API. Here is how to do it:
- Go to the sidebar → Bot.
- Change the name of your bot.
- Click Reset Token. Click Yes, do it to confirm.
- Copy the bot token and save it to your computer.
This token will be inserted into the bot's source code. Also, keep the code secure, as disclosing it can expose your bot and Discord server to security risks.
Now, enable Developer Mode to avoid payment related to your Discord bot's SKUs. Here is how to do it:
- Log in to your Discord app → User Settings → Advanced.
- Turn on Developer Mode.
- Enable the Application Test Mode toggle.
- Enter your Application ID. Set the URL Origin Type as Localhost and the
Port Number as 8080.
- Click Activate.
2. Configure Bot Permissions
After configuring the application, adjust the Discord bot account permissions and authentication method. Here is how to do it:
- On the Applications page, select OAuth2 → General in the sidebar.
- Under the Default Authorization Link, select In-
App Authorization as the method.
- Check the bot checkbox.
- Select the Bot Permissions according to your needs.
- Click Save Changes.
- Go to the sidebar → OAuth2 → URL Generator.
- Check bot as the scope of your application.
- Review the same checkboxes for Bot Permissions.
- Copy the Generated URL and save it to your computer. It should contain your bot's client ID.
Important! Avoid granting Administrator permissions to the bot, as it could modify your server's settings.
Additionally, go to the Bot section in the sidebar and grant the bot Privileged Gateway Intents. Enable all intents if you are unsure which one your bot will use. However, keep in mind that this will grant the bot access to various Discord data.
Now, open the authentication link with a web browser to invite the bot to your Discord server and grant it the necessary permissions.
From the dropdown menu, select the server you want to add the bot to and click Continue. Review the permissions you will grant the bot. If you want to revoke any of them, uncheck the corresponding boxes. Then, click Authorize to confirm.
3. Choose a Programming Language
JavaScript and Python are popular programming languages for creating a Discord bot. Although you can use C++, the available wrappers for the Discord API only support these two languages.
Discord API wrappers simplify the interaction between software and your code, making development easier. Since the language and wrapper don't affect your bot's functionality, choose one based on your familiarity and preferences.
For beginners, we recommend using Python, one of the simplest and best programming languages to learn. It is easier to read and maintain than JavaScript, which simplifies the debugging process. We will also use Python for this tutorial.
Before continuing, download Python and a code editor. When choosing an editor, select one with features that simplify your coding process, such as syntax highlighting, autocomplete, error detection, and module integration.
We recommend Microsoft Visual Studio Code, as it is free and offers various features.
4. Code the Bot
Once the software and tools are ready, create a folder for your Discord bot files. Then, open VSCode to access the folder and create working files:
- Click File → Open Folder.
- Navigate to your new folder directory. Select the folder and click Select Folder.
- Go to the Explorer sidebar and click the add new file icon.
- Create a file named main.py to store all your bot's code. For an advanced bot, you may need several files linked to main.py.
- Create a .env file to store your bot's token. Your Python code will call this file to authenticate the connection with the Discord API.
Important! Leave the .env file name blank. Otherwise, the bot code won't find it and read the environment variable.
```python
# Import the necessary modules
import discord
import os
from discord.ext import commands
from dotenv import load_dotenv
# Create a Discord client instance and set the command prefix
intents = discord.Intents.all()
client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix='!', intents=intents)
# Set the confirmation message when the bot is ready
@bot.event
async def on_ready():
print(f'Connected as {bot.user.name}')
# Set the commands for your bot
@bot.command()
async def greet(ctx):
response = 'Hello, I am your Discord bot!'
await ctx.send(response)
@bot.command()
async def command_list(ctx):
response = 'You can use the following commands: \n !greet \n !command_list \n !features'
await ctx.send(response)
@bot.command()
async def features(ctx):
response = 'I am a simple Discord chat bot! I will respond to your commands!'
await ctx.send(response)
# Get the token from the .env file
load_dotenv()
bot.run(os.getenv('TOKEN'))
```
Depending on your Discord bot's functionality, the code may vary. For this tutorial, we will show you how to make a Discord bot that responds to a simple command:
Code explanation:
- The import keywords import code from a module and add it to your bot file, allowing you to use functions without manually writing them. For example, we import the Discord.py library to enable the bot.command decorator.
- We define the variables that the code will use, such as the Discord bot intents, the client, and the bot itself.
- The @bot.event decorator defines events that trigger the corresponding async function. In the snippet, we instruct the bot to print a confirmation message when it runs successfully.
- The @bot.command decorator sets the command that triggers the bot. We also determine how and when the bot responds.
- The load_dotenv function reads the environment variable from the .env file. In this case, it gets the token.
- Using the os.getenv method, the code extracts the token value and uses it to run the bot with the bot.run.
In addition to responding to commands, you can add advanced features like voice control or input fields. For more information about features, check the discord.py.
In the .env file, paste the following snippet. Replace yourtoken with the authentication key:
```
TOKEN=yourtoken
```
To verify if your code works correctly, click the Run Python File button in the top right corner of VSCode. However, you need to install the dependencies to run the bot.
Pro Tip
If you are in a team environment and continuously updating the Discord bot, we recommend creating a Git repository to simplify the development process. Read our Git tutorials to learn more about it.
How to Host a Discord Bot
Host your Discord bot so it is accessible 24/7. For this tutorial, we will use a HolyHosting VPS hosting plan running Ubuntu 22.04. For other hosting service providers and operating systems, the steps may differ.
Hello! Sure, I can help you with that. Here are the translated and adjusted guides according to your instructions:
1. Get VPS Hosting
While you can create a hosting server for your Discord bot on your local computer, the system needs to be active 24 hours a day. This can cause long-term hardware damage and requires a lot of effort to manage.
A hosting service for your Discord bot, like a VPS, is more convenient and time-efficient. The provider takes care of the server, allowing you to focus on developing and optimizing your bot.
However, choosing one can be difficult, as several providers offer hosting servers for Discord bots. To choose the best VPS hosting for your
Discord bots, consider their features, security, uptime, and price.
Check out our tutorial on the 10 best VPS hosting providers for more information about the options. For example, HolyHosting offers VPS hosting plans starting at $6.49/month with various features:
- Live Snapshot: Users can capture the current state of their server for easy restoration.
- Reliable Hardware: HolyHosting VPS uses SSD storage and a high-performance CPU to ensure optimal performance and uptime.
- Multiple Data Centers: HolyHosting users can choose from various data center locations to minimize latency.
- DDoS Protection: Our VPS uses a built-in firewall and traffic filtering for DDoS protection.
- SSH Support: Users can connect to their VPS via the secure shell (SSH) protocol to efficiently manage their remote server.
- FTP Access: All HolyHosting VPS plans support FTP, allowing users to easily transfer files between systems.
- Dedicated IP: Users get a dedicated IP address to eliminate Cloudflare and Discord server rate limiting.
- Different servers invite your bot, you need more resources to handle the requests.
At HolyHosting, our VPS plans are easily upgradeable to ensure the scalability of your Discord bot.
After purchasing a hosting plan at HolyHosting, select your new server from the VPS menu in the top bar. Then, complete the HolyHosting VPS setup process through hPanel, our intuitive custom control panel.
2. Set Up the VPS Environment
Deploying the Discord bot on a VPS requires setting up the hosting environment to ensure the necessary software is installed. The software varies depending on your bot's language and functionality.
For a Discord.js bot, install Node.js and Node Package Manager. Meanwhile, here is what you need for a Python one:
- Python Interpreter: An environment that converts your Python code into a machine-readable format, allowing your Discord bot to run.
- Pip Package Manager: A package management system used to install modules and dependencies for your Python application.
- Virtualenv: A tool for creating an isolated private virtual environment for your Python application. It allows you to avoid installing Python packages globally, which could affect other projects.
Suggested Reading: Before continuing, read our Linux Commands tutorial to learn more about their functions.
To install the components, connect to your server using SSH applications such as
PuTTY or Terminal. HolyHosting users can find the login credentials in the SSH Access tab in their VPS overview menu.
The VPS access section in hPanel
Once connected, run the following commands to update your package manager and install the necessary software to host your Discord bot:
```bash
sudo apt update
sudo apt upgrade
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt install python3 python3-dev python3-venv python3-pip -y
```
Then, follow these steps to create a virtual environment for your Python project:
1. Run this command to create a new directory to store the files:
```bash
sudo mkdir DiscordBot
```
2. Change the current directory to the new one using this command:
```bash
cd DiscordBot
```
3. Set up the new virtual environment with the venv argument:
```bash
sudo python3 -m venv ./venv
```
4. Activate the virtual environment using the source command:
```bash
source ./venv/bin/activate
```
Your command line should now start with (venv). If the source command is not found, navigate to the directory path ~/DiscordBot/venv/bin using the cd command and run the following:
```bash
source activate
```
PuTTY showing the venv command line
3. Upload the Discord Bot
After setting up the virtual environment, move the token and bot files to the new directory. You can do this using the rsync command, the scp protocol, or an SFTP client.
We recommend using Secure File Transfer Protocol (SFTP) as it offers a graphical user interface and is more secure than standard FTP. The visual interface makes the process simpler and more beginner-friendly.
For this tutorial, we will use FileZilla to transfer the files via SFTP. Here are the steps:
1. Download and install FileZilla.
2. Open FileZilla. Enter your server's IP address, username, password, and port number. By default, the port number is 22.
3. Click "Quickconnect".
4. Once connected, locate the new directory ./venv under the "Remote site" tab.
5. Drag and drop the bot files from your local computer to the remote directory.
6. Wait until the process is complete. The file transfer status is found in the box under the connection tab.
Then, go back to your SSH client or Terminal. Move to the bot directory and install all the dependencies. In this tutorial, we will install the discord.py wrapper and dotenv with this command:
```bash
sudo pip install discord.py python-dotenv
```
Pro Tip: Having trouble typing bash commands or managing your Linux VPS? Enter AI commands for VPS management in HolyHosting's VPS assistant to easily generate commands or code.
4. Start the Bot
To run the bot, set the current directory to the location of the main.py file and run the following command. If you use a different file name, adjust it accordingly:
```bash
python3 main.py
```
The Terminal should return the confirmation message written in the bot file, similar to the following:
PuTTY showing the Discord bot running correctly
If you open the Discord server where the bot is located, it will appear online. To verify if your bot works correctly, enter a command and it should respond as expected.
However, this bot is only active in your current session. If you close the SSH client or Terminal, the session will end and shut down the bot. You can use different tools to keep your bot running:
- Linux Screen: A tool that allows users to create multiple virtual terminals within a session. Virtual terminal processes run in the background after logging out and disconnecting from the server.
- tmux: Terminal Multiplexer works similarly to Screen, allowing users to create virtual sessions and run background processes. It is easier to use than Screen, but lacks some features and is less stable.
- PM2: A Node.js application process manager that keeps your application running constantly. It is native to JavaScript but works with other programming languages, including Python.
- Docker: A containerization tool that turns your Discord bot into a daemon. It allows your bot to run in the background and restart automatically after a system failure.
In this tutorial, we will use Linux Screen, which is the simplest and most compatible with different environments. Here are the steps to install and use Screen to run your Discord bot on an Ubuntu VPS server:
1. In Terminal or the SSH application, run this command to install Screen:
```bash
sudo apt-get install screen
```
2. Run this command to create a new session:
```bash
screen
```
3. Use this command in the virtual Terminal to change the working directory:
```bash
cd /DiscordBot/venv
```
4. Start your Discord bot using the following command:
```bash
python3 main.py
```
5. Once the bot is running, press Ctrl + A + D to detach the Screen session.
Important! For Red Hat Enterprise Linux (RHEL) derivatives like AlmaLinux and CentOS, use yum instead of apt to install Screen.
Now, the session will continue running in the background after disconnecting from the server. To reattach to Screen, open your Terminal or SSH application and enter:
```bash
screen -r
```
Screen allows you to create multiple sessions to run other Discord bots using this command:
```bash
screen -S session1
```
Replace session1 with your session name. Use a descriptive name to help you easily identify sessions and their processes. To list the current user's sessions, use the following:
```bash
screen -ls
```
Monitor and Maintain the Bot's Performance
After deploying your Discord bot, it is crucial to monitor it regularly to ensure optimal performance. This will help you identify potential issues quickly before they affect your bot's usability.
The first monitoring task is to enable the Python logging module to track your Discord bot's events and errors. This provides information about your bot's functionality to facilitate debugging and troubleshooting.
For example, add the following code snippet to your bot file to log command execution errors in a bot.log file and on the Discord server:
```python
# Import the Python logging module
import logging
# Configure logging options
logging.basicConfig(level=logging.INFO,
format='[%(asctime)s] [%(levelname)s]: %(message)s',
handlers=[
logging.FileHandler('bot.log'), # Save logs to a file
logging.StreamHandler() # Display logs in the console
])
# Import the Python logging module
import logging
# Configure logging options
logging.basicConfig(level=logging.INFO,
format='[%(asctime)s] [%(levelname)s]: %(message)s',
handlers=[
logging.FileHandler('bot.log'), # Save logs to a file
logging.StreamHandler() # Display logs in the console
])
# Configure how the bot behaves when encountering an error
@bot.event
async def on_command_error(ctx, error):
error_message = f'Error occurred during command processing: {error}'
logging.error(error_message)
await ctx.send(error_message)
# Configure how the bot behaves when encountering an error @bot.event async def on_command_error(ctx, error): error_message = f'Error occurred during command processing: {error}' logging.error(error_message) await ctx.send(error_message)
# Configure how the bot behaves when encountering an error
@bot.event
async def on_command_error(ctx, error):
error_message = f'Error occurred during command processing: {error}'
logging.error(error_message)
await ctx.send(error_message)
```
Additionally, use tools like UptimeRobot to monitor the Discord bot's uptime. To track its usage and activity, use an application performance monitoring (APM) tool like Grafana. Since the setup process for each tool differs, consult their manuals for instructions.
Also, monitor the virtual private server (VPS) resource usage to ensure the bot has enough resources to run optimally. Some important metrics to track include CPU usage, RAM consumption, storage load, and network conditions.
If your server does not have a control panel, use Python's psutil or Linux commands like vmstat. These methods do not offer a graphical user interface (GUI), making the process complicated and not beginner-friendly.
Web hosting providers usually provide a control panel to track server usage. For example, HolyHosting offers a VPS resource usage monitoring feature in hPanel.
We recommend that you submit your application to a bot listing website like top.gg to make it accessible to other Discord users.
Conclusion
Inviting bots to your Discord server allows you to add new features and simplify moderation tasks. Although there are many pre-programmed bots available, you may need to create a custom one for your particular use case.
In this article, we have explained the steps to create and host a Discord bot on a VPS
Linux.
Here is a summary:
1. Create a Discord account and application on the developer portal.
2. Configure the bot's permissions and invite it to your Discord server.
3. Choose a programming language and an integrated development environment (IDE).
4. Write the code for your Discord bot.
5. Acquire a hosting service for your Discord bot, such as HolyHosting VPS.
6. Install the dependencies to set up the hosting server environment.
7. Upload the bot files and token via SFTP.
8. Start your Discord bot and use Screen to keep it running 24/7.
9. Monitor and maintain the bot's performance.
We hope this article has helped you develop and host your Discord bot. If you have any questions, leave us a comment. Good luck!
Come chat with us and we will get back to you as soon as possible!
Contact SupportHello! In the following guide, we will explain how to get the roles on our Discord rank. This is super simple from our client area.
Hello! In the following guide we will explain how to get the client role on our Discord, this is super simple! Access the client area. To access the
Minecraft is a highly flexible game that allows users to customize almost everything about it. This is typically done with mods, which are needed in the launcher. These require Forge or Fabric versions of Minecraft to fully work, but may require more memory.