Deploying a discord.js Bot on Pterodactyl
Step-by-step guide to deploying a Node.js discord.js bot on VisiHost's Pterodactyl panel with environment variables, package management, and auto-restarts.
Deploying a discord.js bot on VisiHost takes four basic steps: upload your bot files, configure your BOT_TOKEN in the Startup tab, install packages, and press Start. This guide covers the full setup process from scratch.
Prerequisites#
Before deploying, ensure you have:
- An active container from Free Bot Hosting or Paid Discord Bot Hosting.
- Your bot token from the Discord Developer Portal.
- A project with a valid
package.jsonfile. VisiHost containers support modern Node.js versions (including Node.js 18, 20, and 22).
Deployment Steps#
Step 1: Prepare Your Project Files#
Make sure your package.json specifies the entry file (usually index.js, main.js, or bot.js).
Example package.json:
{
"name": "my-discord-bot",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "^14.16.0",
"dotenv": "^16.4.5"
}
}Note: Do not upload your local node_modules folder. Your packages will install cleanly directly inside the Linux container, avoiding operating system binary conflicts.
Step 2: Upload Files via File Manager or SFTP#
- Log into your control panel at paid.visihost.in.
- Click on your bot container to open the dashboard.
- Open the Files tab on the left menu.
- Drag and drop your project files (such as
index.js,package.json, and any source subdirectories) directly into the browser.
For larger bots, you can connect via SFTP using the credentials located under the Settings tab with an SFTP client such as FileZilla, Cyberduck, or WinSCP.
Step 3: Configure Startup & Environment Variables#
- Go to the Startup tab in your container dashboard.
- Confirm the JS File setting matches your entry script (default is
index.js). - Under Environment Variables, locate or add your
BOT_TOKEN:- Variable Name:
BOT_TOKEN - Value:
YourDiscordBotTokenHere
- Variable Name:
Inside your code, read the token securely through process.env:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.once('ready', () => {
console.log(`Ready! Logged in as ${client.user.tag}`);
});
client.login(process.env.BOT_TOKEN);Step 4: Install Dependencies and Start#
- Switch to the Console tab.
- If automatic package installation is enabled, your dependencies install automatically when the container boots. You can also run the command manually in the console command bar:
npm install discord.js dotenv - Once the packages finish installing, click the Start button at the top of the panel.
- Watch the console logs to confirm the bot logs in successfully.
Troubleshooting Common Errors#
1. Privileged Intents Error (Disallowed Intents)#
- Symptom: The console shows
Privileged intent provided is not enabledorDisallowedIntentsException. - Solution: Go to the Discord Developer Portal, select your bot, open the Bot tab, scroll down to Privileged Gateway Intents, and toggle on Message Content Intent and Server Members Intent as required by your code.
2. Missing Module Error (MODULE_NOT_FOUND)#
- Symptom: The bot crashes on startup with
Cannot find module 'package-name'. - Solution: Ensure the missing package is listed in
package.json, then runnpm install package-namein the console.
3. Native C++ Compilation (better-sqlite3, @discordjs/opus)#
- VisiHost container images come equipped with standard build tools (
gcc,g++,make, and Python) to ensure native Node.js modules compile without manual intervention.
Frequently Asked Questions (FAQ)#
Should I upload my node_modules folder to the panel?#
No. Never upload node_modules from your local machine. Operating systems (like Windows or macOS) build native binary packages differently than Linux. Always upload only your package.json and run npm install directly inside the container to build clean Linux binaries.
How do I configure process restart managers like PM2?#
VisiHost containers run inside an automated Pterodactyl daemon watchdog that monitors your Node.js process 24/7. You do not need to install PM2 or forever; the daemon handles automatic restarts and crash recovery natively.
What Node.js versions are supported?#
VisiHost Node.js containers support Node.js 18, 20, and 22 LTS releases. You can switch or confirm your Node.js runtime version directly in the container's Startup tab.
