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 your Main file extension: a .py file runs your bot with Python, everything else with Node.js (.ts files are launched via ts-node). Simply pick the Docker image matching your language and desired version.
| 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.
Automatic dependency installation
The Automatic dependency installation variable (AUTO_INSTALL), checked by default, runs npm install (or pip install) on each startup. Uncheck it if you manage your dependencies yourself: startups will be much faster.
Clean reinstall
The Clean reinstall variable (CLEAN_INSTALL) deletes node_modules and package-lock.json (or .local for Python) before installation. Use it to repair broken dependencies, typically a NODE_MODULE_VERSION / ERR_DLOPEN_FAILED error (see Troubleshooting).
Remember to uncheck it after a successful startup, otherwise all dependencies are re-downloaded on every boot.
Native modules to compile
The Native modules to compile variable (NPM_APPROVE_SCRIPTS) lists the npm packages allowed to run their build scripts, separated by spaces:
better-sqlite3 canvas sqlite3
npm blocks install scripts by default (install scripts blocked because they are not covered by allowScripts message in the console). Without this approval, native modules stay compiled for another Node version and the bot crashes at startup. Listed packages are approved and then rebuilt (npm rebuild) on each startup.
Pre-start command
The Pre-start command variable (PRE_START_CMD) runs a shell command of your choice in /home/container right before the bot launches. Ideal for build steps:
npm run build
npx prisma generate
npm ci --omit=dev
npm rebuild better-sqlite3
Leave it empty if you don't need it.
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
- Clean reinstall (if enabled) —
node_modules/.localdeletion - Build script approval — Packages listed in Native modules to compile are allowed
- Dependency installation (if Automatic installation is enabled):
- Node.js →
npm install(frompackage.json) + additional packages - Python →
pip install(fromrequirements.txt) + additional packages
- Node.js →
- Native module rebuild —
npm rebuildon the listed packages - Pre-start command (if set) — Execution of your custom command
- Bot launch — Execution of the main file (
node,ts-nodeorpythondepending on the extension)
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.
ERR_DLOPEN_FAILED / NODE_MODULE_VERSION error
Error: The module 'better_sqlite3.node' was compiled against a different Node.js version
using NODE_MODULE_VERSION 141. This version of Node.js requires NODE_MODULE_VERSION 127.
A native module (better-sqlite3, canvas, sqlite3...) was compiled for another Node version, often because node_modules was uploaded from your PC or the Docker image changed. To fix it:
- Check Clean reinstall
- Enter the affected modules in Native modules to compile (e.g.,
better-sqlite3 canvas sqlite3) - Restart the server
- Once the bot is online, uncheck Clean reinstall
Never upload your node_modules folder from your PC: it contains binaries compiled for your machine, not for the server. Only upload your code and your package.json, the installation happens on the server.
"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