How to Deploy a discord.js Bot to a Hosting Server
A step-by-step guide to deploying your discord.js bot from your local machine to a production Pterodactyl hosting environment.
How to Deploy a discord.js Bot
You have finished coding your bot locally and it works perfectly. Now you want it online 24/7. Here is how to deploy it using the VisiHost Pterodactyl panel.
Step 1: Prepare Your Files
- Do NOT upload node_modules. The server installs its own dependencies.
- Ensure you have a package.json listing all required packages.
- Use environment variables for your bot token. Create a .env file and use the dotenv package.
Zip your bot folder excluding node_modules.
Step 2: Upload to the Panel
- Log in to the VisiHost Pterodactyl Panel.
- Select your Discord bot server.
- Navigate to Files.
- Click Upload and select your zip file.
- Click the three dots next to the zip and select Unarchive.
Step 3: Configure Startup
- Go to the Startup tab.
- Set Startup File to your main file (e.g. index.js or bot.js).
- Ensure the Node.js version is compatible. discord.js v14 requires Node.js 16.11.0 or higher.
Step 4: Start
- Go to the Console tab.
- Click Start.
- The server runs npm install automatically, then executes your startup file.
Troubleshooting
Module Not Found: Add the missing module to your package.json and click Start again.
Wrong Node Version: Update the Node.js version in your Pterodactyl environment settings.
Conclusion
Deploying a discord.js bot is straightforward with Pterodactyl. Check out VisiHost Discord Bot Hosting plans starting at Rs 10 per month.
Keep Your Discord Bot Online 24/7
No sleep scripts needed. High-performance hosting for Node.js and Python.
Explore more about VisiHost
Check out our other affordable hosting packages and guides.