Host a Discord Bot
Welcome to YorkHost! This guide walks you through deploying your Discord bot on our high-performance infrastructure, whether you're using Node.js or Python. Thanks to our intuitive panel and optimized servers, your bot will be online in minutes.
Prerequisites
Before you begin, make sure you have:
- A Discord bot created on the Discord Developer Portal
- Your bot's token (available in the "Bot" tab of your application)
- Your source code, either on a Git repository (GitHub, GitLab...) or ready to be uploaded manually
- An active Discord Bot plan on YorkHost — our plans include a full management panel, DDoS protection, and responsive support
1. Choose your language
The language is automatically detected based on the Docker image you select in your server settings. You don't need to configure anything manually — YorkHost handles everything.
| Docker Image | Language | Use case |
|---|---|---|
| Node.js 18 | JavaScript / TypeScript | discord.js, eris |
| Node.js 21 | JavaScript / TypeScript | discord.js (recent version) |
| Node.js 22 | JavaScript / TypeScript | discord.js (latest LTS) |
| Node.js 24 | JavaScript / TypeScript | discord.js (latest) |
| Python 3.12 | Python | discord.py, nextcord, pycord |
To change the language, simply modify the Docker image in your server settings on the YorkHost Panel, then reinstall the server.
2. Deploy your bot
You have two methods to upload your code to the server.
Method 1: Via a Git repository (recommended)
This is the simplest method. Enter your repository URL in the Git repo address variable:
https://github.com/your-name/your-bot
The server will automatically clone your repository on installation. On each restart, a git pull is performed to fetch the latest changes.
Private repository? Also enter your Git username and a Personal Access Token in the corresponding variables.
Specific branch? Enter it in the Git branch variable (e.g., main, dev, production). Leave empty for the default branch.
Method 2: Manual upload
If you don't use Git:
- Leave the Git repo address variable empty
- Access the file manager on the YorkHost Panel
- Upload your files (drag and drop or "Upload" button)
- Start your server
3. Configure variables
Go to the Startup tab of your server on the YorkHost Panel to modify the variables.
Main file
The Main file variable (MAIN_FILE) specifies which file to launch at startup.
| Language | Common examples |
|---|---|
| Node.js | index.js, bot.js, src/index.js |
| TypeScript | index.ts, bot.ts |
| Python | main.py, bot.py, src/bot.py |
Default: index.js. Modify it according to your project.
Additional packages
The Additional packages variable (PACKAGES) allows you to install dependencies at startup, separated by spaces. The package manager used (npm or pip) is automatically detected.
Node.js examples:
discord.js dotenv mongoose express
Python examples:
discord.py python-dotenv aiohttp requests
If your project contains a package.json (Node.js) or requirements.txt (Python), the dependencies listed there are automatically installed on each startup. The Packages variable is mainly useful for adding one-off dependencies without modifying those files.
4. Manage your Discord token
Your bot token is not configured in the server variables. It should be in your code, ideally via a .env file at the root of your project.
Create a .env file
Via the file manager on the YorkHost Panel, create a .env file containing:
DISCORD_TOKEN=your_token_here
Read the token in your code
Node.js (with the dotenv package):
require('dotenv').config();
client.login(process.env.DISCORD_TOKEN);
Python (with the python-dotenv package):
from dotenv import load_dotenv
import os
load_dotenv()
client.run(os.getenv('DISCORD_TOKEN'))
Never commit your .env file to Git. Add it to your .gitignore.
5. Understanding the startup cycle
Here's what happens each time you start your server on YorkHost:
- Git pull — If a Git repository is configured, the latest changes are fetched
- Dependency installation:
- Node.js →
npm install(frompackage.json) + additional packages - Python →
pip install(fromrequirements.txt) + additional packages
- Node.js →
- Bot launch — Execution of the main file
This process is fully automatic. You just need to push your changes to Git and restart from the Panel.
6. Troubleshooting
My bot doesn't start
- Check the main file: does the name in the
MAIN_FILEvariable match your file? - Check the console: errors are displayed in the YorkHost Panel console
- Check the Docker image: make sure you're using a Node.js image for JavaScript, or Python for Python
"Cannot find module" error
Your dependency is not installed. Add it to the Packages variable or to your package.json / requirements.txt, then restart.
"TOKEN_INVALID" error
Your Discord token is invalid or expired. Regenerate it on the Discord Developer Portal and update your .env file.
My bot disconnects after a few hours
Make sure your code properly handles reconnection. With discord.js, this is handled automatically. With discord.py, make sure you're not accidentally using client.close().
On YorkHost, automatic restart is enabled by default. If your bot crashes, it will be automatically restarted.
Git pull overwrites my changes
If you modify files directly on the Panel while a Git repository is configured, the automatic git pull on restart may overwrite your changes. Two solutions:
- Make your changes on Git, not on the Panel
- Remove the Git address from the variable to switch to manual upload mode
TypeError: Cannot read properties of undefined
In Node.js, this often means you're using a version of discord.js that is incompatible with your Node.js version. Check compatibility:
| discord.js | Minimum Node.js |
|---|---|
| v14 | Node.js 16.11+ |
| v15 | Node.js 18+ |
7. Best practices
- Use a
.envfile to store your tokens and API keys, never hardcode them - Use
package.jsonorrequirements.txtto list your dependencies rather than the Packages variable - Enable the required Intents on the Discord Developer Portal (Message Content, Server Members, etc.)
- Handle errors in your code to prevent the bot from crashing on unhandled exceptions
- Test locally before deploying to the server
Why choose YorkHost for your Discord bot?
- French infrastructure: servers hosted in France for minimal latency
- DDoS protection: your bot is protected against attacks
- Intuitive panel: simplified management via our web panel with console, file manager, and SFTP
- Responsive support: our team is available to help you via tickets and Discord
- Automatic deployment: native Git integration for one-click updates
Discover our Discord Bot plans
Need help?
If you encounter a problem not covered by this guide, contact our support:
- Tickets: from your client area
- Discord: join our server for community help