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β
- Go to the Discord Developer Portal
- Click New Application
- Give your application a name
- In the left menu, go to Bot
- Click Add Bot
- Copy your bot's Token (keep it secret!)
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:
- Enable the Privileged Gateway Intents you need:
PRESENCE INTENT: To see member statusSERVER MEMBERS INTENT: To access member informationMESSAGE CONTENT INTENT: To read message content
Intents are necessary for your bot to receive certain events from Discord.
Invite your bot to a serverβ
- In the left menu, go to OAuth2 > URL Generator
- Check
botin Scopes - Select the necessary permissions in Bot Permissions
- Copy the generated URL and open it in your browser
- Select the server to invite the bot to
Prepare your bot for hostingβ
Recommended project structureβ
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:
- Go to yorkhost.fr/en/discord
- Choose the plan that fits your needs (minimum 512 MB RAM recommended)
- Complete your order
- 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β
- In the panel, go to Files
- Delete example files if present
- Upload your files:
index.jspackage.json- Other project files (except
node_modules)
Via SFTPβ
- In the panel, go to Settings
- Note the SFTP connection information
- Use an FTP client like FileZilla or WinSCP
- Transfer your files
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!
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:
1to automatically update on restart
If you upload your files manually, leave Git Repo Address empty.
4. Install dependenciesβ
Pterodactyl will automatically install dependencies at startup. If not:
- Go to Console
- The server will execute
npm installautomatically - Wait for the installation to complete
Start your botβ
- In the panel, click Start
- Monitor the console to see logs
- You should see the message:
β Bot logged in as YourBot#1234
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β
- In the panel, go to Startup
- Verify that the automatic restart option is enabled
- 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β
- Stop the bot
- Upload modified files
- Restart the bot
Method 2: Via SFTPβ
- Connect via SFTP
- Replace modified files
- Restart the bot from the panel
Method 3: Via Git (recommended)β
If your bot is on GitHub/GitLab:
- Access the server console
- Execute
git pullto fetch changes - Restart the bot
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.jsonfile 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
.envto store the token - β
Add
.envto.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:
- Check server logs in the Pterodactyl console
- Review Discord.js documentation for your version
- Contact YorkHost support for hosting issues