Skip to main content

Host a Discord Bot on Pterodactyl

This guide explains how to host and configure a Discord bot on a Pterodactyl panel.

Prerequisites​

Create your Discord bot​

  1. Go to the Discord Developer Portal
  2. Click New Application
  3. Give your application a name
  4. In the left menu, go to Bot
  5. Click Add Bot
  6. Copy your bot's Token (keep it secret!)
Token Security

Never share your Discord token. If you lose it or it gets exposed, regenerate it immediately from the Developer Portal.

Enable required intents​

In the Bot section of the Developer Portal:

  1. Enable the Privileged Gateway Intents you need:
    • PRESENCE INTENT: To see member status
    • SERVER MEMBERS INTENT: To access member information
    • MESSAGE CONTENT INTENT: To read message content
info

Intents are necessary for your bot to receive certain events from Discord.

Invite your bot to a server​

  1. In the left menu, go to OAuth2 > URL Generator
  2. Check bot in Scopes
  3. Select the necessary permissions in Bot Permissions
  4. Copy the generated URL and open it in your browser
  5. Select the server to invite the bot to

Prepare your bot for hosting​

Your project should contain at minimum:

my-discord-bot/
β”œβ”€β”€ index.js # Main entry point
β”œβ”€β”€ package.json # Dependencies and scripts
β”œβ”€β”€ .env # Environment variables (do not commit!)
└── node_modules/ # Installed dependencies

Example package.json​

{
"name": "my-discord-bot",
"version": "1.0.0",
"description": "My Discord bot",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "^14.14.1",
"dotenv": "^16.3.1"
},
"engines": {
"node": ">=18.0.0"
}
}

Minimal code example (index.js)​

require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});

client.on('ready', () => {
console.log(`βœ… Bot logged in as ${client.user.tag}`);
});

client.on('messageCreate', (message) => {
if (message.author.bot) return;

if (message.content === '!ping') {
message.reply('Pong! πŸ“');
}
});

client.login(process.env.DISCORD_TOKEN);

Configuration on Pterodactyl​

1. Order your Discord Bot server​

To host your Discord bot on YorkHost:

  1. Go to yorkhost.fr/en/discord
  2. Choose the plan that fits your needs (minimum 512 MB RAM recommended)
  3. Complete your order
  4. Once the server is created, access your game panel

Your server will be automatically configured with the Node.js image needed to run your Discord bot.

2. Upload your files​

Via web interface​

  1. In the panel, go to Files
  2. Delete example files if present
  3. Upload your files:
    • index.js
    • package.json
    • Other project files (except node_modules)

Via SFTP​

  1. In the panel, go to Settings
  2. Note the SFTP connection information
  3. Use an FTP client like FileZilla or WinSCP
  4. Transfer your files
Tip

Never upload the node_modules folder. Dependencies will be installed automatically on the server.

3. Configure Startup Parameters​

In the panel, go to Startup Parameters. Here are the settings to configure:

Image​

  • Choose Node Js 24 (or 18, 20)
  • This is the Node.js version that will run your bot

Main file​

  • Set to index.js (or your main file name)
  • This is the file that will be launched at startup

Additional Node packages​

  • Leave empty if your dependencies are in package.json
  • Otherwise, you can force versions: discord.js@14.14.1

Discord Token (DISCORD_TOKEN)​

  • Paste your token copied from the Developer Portal
  • Never share it!
Simple configuration

If you're a beginner, leave all other parameters at their default values. You only need to modify Main file and DISCORD_TOKEN.

Using Git (optional)​

If your code is on GitHub/GitLab:

  • Git Repo Address: https://github.com/username/my-bot.git
  • Install Branch: main (or your branch)
  • Auto Update: 1 to automatically update on restart
info

If you upload your files manually, leave Git Repo Address empty.

4. Install dependencies​

Pterodactyl will automatically install dependencies at startup. If not:

  1. Go to Console
  2. The server will execute npm install automatically
  3. Wait for the installation to complete

Start your bot​

  1. In the panel, click Start
  2. Monitor the console to see logs
  3. You should see the message: βœ… Bot logged in as YourBot#1234
Verification

Go to Discord and verify that your bot is online (green status).

Bot management​

Automatic restart​

To automatically restart the bot in case of crash, modify your package.json:

{
"scripts": {
"start": "node index.js"
}
}

Pterodactyl will automatically restart the process if the option is enabled in server settings.

Enable automatic restart​

  1. In the panel, go to Startup
  2. Verify that the automatic restart option is enabled
  3. Configure restart delay if needed

Monitor logs​

Logs are available in the panel's Console. You can:

  • View startup messages
  • Detect errors
  • Monitor bot activity

Update the bot​

Method 1: Via web interface​

  1. Stop the bot
  2. Upload modified files
  3. Restart the bot

Method 2: Via SFTP​

  1. Connect via SFTP
  2. Replace modified files
  3. Restart the bot from the panel

If your bot is on GitHub/GitLab:

  1. Access the server console
  2. Execute git pull to fetch changes
  3. Restart the bot
Automation

You can create a script to automate updates via a Discord webhook or custom command.

Common issues​

Bot doesn't start​

Checks:

  • Discord token is correct and valid
  • package.json file is valid (check JSON syntax)
  • Dependencies are installed (npm install)
  • Node.js version is compatible (18+ for Discord.js v14)

Solution: Check the logs in the console to identify the exact error.

Invalid token​

Error: Used disallowed intents

Solution: Enable the required intents in the Discord Developer Portal.

Memory error​

JavaScript heap out of memory

Solution: Increase RAM allocated to the server in Pterodactyl settings.

Bot disconnects regularly​

Checks:

  • Allocated RAM is sufficient (minimum 512 MB)
  • No errors in logs
  • Network connection is stable

Solution: Check logs to identify errors and adjust resources if needed.

Optimization and best practices​

Error handling​

Add error handlers to avoid crashes:

client.on('error', (error) => {
console.error('Discord error:', error);
});

process.on('unhandledRejection', (error) => {
console.error('Unhandled rejection:', error);
});

Using PM2 (optional)​

PM2 is a process manager that can automatically restart your bot:

{
"scripts": {
"start": "pm2 start index.js --name my-bot"
}
}

Logging​

Use a logging library like Winston for better log management:

npm install winston

Database​

If your bot uses a database:

  • Use environment variables for credentials
  • Use SQLite for small projects
  • Use MySQL/PostgreSQL for larger projects

Security​

Token protection​

  • βœ… Always use .env to store the token
  • βœ… Add .env to .gitignore
  • βœ… Never commit the token to GitHub
  • ❌ Never share your token

Bot permissions​

Only grant strictly necessary permissions:

  • Avoid administrator permissions unless absolutely necessary
  • Use the principle of least privilege
  • Regularly review permissions

Rate limiting​

Discord applies rate limits. Make sure to:

  • Not send too many messages quickly
  • Use Discord.js caching features
  • Properly handle 429 (Too Many Requests) errors

Useful resources​

Support​

If you encounter issues:

  1. Check server logs in the Pterodactyl console
  2. Review Discord.js documentation for your version
  3. Contact YorkHost support for hosting issues