Skip to main content

Host your Discord bot 24/7 on a reliable VPS with no downtime.

See our VPS

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 ImageLanguageUse case
Node.js 18JavaScript / TypeScriptdiscord.js, eris
Node.js 21JavaScript / TypeScriptdiscord.js (recent version)
Node.js 22JavaScript / TypeScriptdiscord.js (latest LTS)
Node.js 24JavaScript / TypeScriptdiscord.js (latest)
Python 3.12Pythondiscord.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.

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:

  1. Leave the Git repo address variable empty
  2. Access the file manager on the YorkHost Panel
  3. Upload your files (drag and drop or "Upload" button)
  4. 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.

LanguageCommon examples
Node.jsindex.js, bot.js, src/index.js
TypeScriptindex.ts, bot.ts
Pythonmain.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
info

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).

warning

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'))
Security

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:

  1. Git pull — If a Git repository is configured, the latest changes are fetched
  2. Clean reinstall (if enabled) — node_modules / .local deletion
  3. Build script approval — Packages listed in Native modules to compile are allowed
  4. Dependency installation (if Automatic installation is enabled):
    • Node.js → npm install (from package.json) + additional packages
    • Python → pip install (from requirements.txt) + additional packages
  5. Native module rebuild — npm rebuild on the listed packages
  6. Pre-start command (if set) — Execution of your custom command
  7. Bot launch — Execution of the main file (node, ts-node or python depending 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_FILE variable 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:

  1. Check Clean reinstall
  2. Enter the affected modules in Native modules to compile (e.g., better-sqlite3 canvas sqlite3)
  3. Restart the server
  4. Once the bot is online, uncheck Clean reinstall
tip

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().

tip

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.jsMinimum Node.js
v14Node.js 16.11+
v15Node.js 18+

7. Best practices​

  • Use a .env file to store your tokens and API keys, never hardcode them
  • Use package.json or requirements.txt to 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