Game Servers & OuiPanelDecember 15, 2025 2 views

How to host a Discord bot (discord.js) on OuiPanel

How to host a Discord bot (discord.js) on OuiPanel

How to Host a Discord Bot (discord.js) on OuiPanel

Estimated Time: 15 minutes
Difficulty: Intermediate ⭐⭐
Server Type: Node.js


📋 Introduction

This guide explains how to host a Discord bot developed with discord.js (JavaScript/Node.js) on OuiPanel. Your bot will be online 24/7.

What You Need

Prerequisite Description
🤖 A Discord bot Created on the Discord Developer Portal
🔑 The bot's token Secret key to connect your bot
📁 The bot's files Your source code (index.js, package.json, etc.)
💻 A Node.js server Ordered on OuiHeberg

🤖 Step 1: Create the Bot on Discord (if not already done)

If you already have your bot and its token, proceed to step 2.

Create the Application

  1. Go to the Discord Developer Portal
  2. Log in with your Discord account
  3. Click on New Application
  4. Give your application a name (e.g., "My Bot")
  5. Click on Create

Image


Create the Bot

  1. In the left menu, click on Bot
  2. Click on Add Bot then Yes, do it!
  3. Your bot is created!

[Screenshot: Bot Section with Add Bot button]


Get the Token

  1. In the Bot section, click on Reset Token
  2. Confirm and copy the displayed token
  3. Keep this token secret! Never share it.

Image

⚠️ Important: The token is like a password. If someone obtains it, they can control your bot. Never put it in public code (GitHub, etc.).


Enable Intents

  1. Still in the Bot section, scroll down to Privileged Gateway Intents
  2. Enable the necessary intents:
    • PRESENCE INTENT (optional)
    • SERVER MEMBERS INTENT (optional)
    • MESSAGE CONTENT INTENT (required to read messages)

Image

⚠️ Important: Without MESSAGE CONTENT INTENT, your bot won't be able to read message content.


Invite the Bot to Your Server

  1. In the left menu, click on OAuth2URL Generator
  2. In Scopes, check bot and applications.commands
  3. In Bot Permissions, check the necessary permissions (or Administrator for all)
  4. Copy the generated URL
  5. Open this URL and invite the bot to your Discord server

Image


📁 Step 2: Prepare the Bot's Files

File Structure

Your bot should have this structure:

📁 MyBot/
├── 📄 index.js         ← Main file (or bot.js, main.js...)
├── 📄 package.json     ← npm dependencies
├── 📄 .env             ← Bot's token (created on the server)
├── 📁 commands/        ← (Optional) Commands folder
└── 📁 events/          ← (Optional) Events folder

File package.json

Create a package.json file with the discord.js and dotenv dependencies:

{
  "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"
  }
}

💡 Adapt "main": "index.js" according to the name of your main file (bot.js, main.js, etc.).


Main File (index.js)

Create your main file with dotenv to load the token:

// Load environment variables from .env
require('dotenv').config();

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

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

// Event: Bot ready
client.once('ready', () => {
    console.log(`✅ Bot connected as ${client.user.tag}`);
});

// Event: Message received
client.on('messageCreate', message => {
    if (message.author.bot) return;
    
    // Use the prefix from .env (optional)
    const prefix = process.env.PREFIX || '!';
    
    if (message.content === `${prefix}ping`) {
        message.reply('🏓 Pong!');
    }
});

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

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

// Connect with the token from .env
client.login(process.env.DISCORD_TOKEN);

⚠️ Important: require('dotenv').config(); must be the first line of your file.


📤 Step 3: Upload the Files to OuiPanel

Using the File Manager

  1. Log in to OuiPanel
  2. Select your Node.js server
  3. In the side menu, click on File Manager

  1. Delete default files (if any)
  2. Click on Upload
  3. Upload your files:
    • index.js (or bot.js, main.js...)
    • package.json
    • Your folders (commands/, events/...) if needed

Image

⚠️ Do not upload: The .env file will be created directly on the server in the next step.


Using SFTP (Recommended for multiple files)

  1. Connect via SFTP with FileZilla
  2. Drag and drop all the content of your bot folder
  3. Ensure all files are successfully uploaded

📖 Check the guide "SFTP Access with FileZilla" for detailed instructions.


🔑 Step 4: Create the .env File (Token)

Never put your token directly in the code! Create a .env file on the server.

Create the .env file

  1. In the File Manager, click on New file
  2. Name it .env (with the dot in front)
  3. Add the following content:
# Discord bot token
DISCORD_TOKEN=your_token_here

# Command prefix (optional)
PREFIX=!

Image

  1. Click on Create or Save

Example with your real token:

DISCORD_TOKEN=MTIzNDU2Nzg5MDEyMzQ1Njc4OQ.ABcdEF.abcdefghijklmnopqrstuvwxyz123456
PREFIX=!

⚠️ Important:

  • No spaces around the =
  • No quotes around the values
  • Never share this file

Final Structure on the Server

📁 Server Root/
├── 📄 .env              ← Contains DISCORD_TOKEN
├── 📄 index.js          ← Your code
├── 📄 package.json      ← Dependencies
└── 📁 node_modules/     ← (created automatically)

⚙️ Step 5: Configure the Startup File

OuiPanel needs to know which file to execute at startup.

Access the settings

  1. In the side menu, click on Configuration
  2. Click on Server Settings

Image


Configure the file to execute

Locate the File to execute field:

Image

Your main file Value to set
index.js index.js
bot.js bot.js
main.js main.js
src/index.js src/index.js
app.js app.js

⚠️ Important: The name must match exactly your file (case-sensitive).


🚀 Step 6: Start the Bot

Launch the server

  1. In the side menu, click on Console
  2. Click on Start

Automatic Installation of Dependencies

Upon first startup, the server automatically runs npm install:

> npm install
added 45 packages in 3s

> node index.js
✅ Bot connected as MyBot#1234

Image

✅ Step 7: Verify the Bot is Working

In the OuiPanel Console

You should see:

✅ Bot connected as MyBot#1234

On Discord

  1. Open Discord
  2. Your bot should appear online (green dot)
  3. Test a command: !ping
  4. The bot responds: 🏓 Pong !

Image


🔧 Troubleshooting

The bot doesn't start

❌ Error ✅ Solution
Cannot find module 'discord.js' Check package.json and restart
Cannot find module 'dotenv' Add dotenv to package.json
Error: Cannot find module './index.js' Incorrect startup file configured
ENOENT: no such file or directory The specified file does not exist

Token Error

❌ Error ✅ Solution
An invalid token was provided Check the token in .env
TOKEN_INVALID Regenerate the token on the Discord portal
Used disallowed intents Enable intents on the Discord portal

The bot doesn't read messages

❌ Cause ✅ Solution
MESSAGE CONTENT INTENT disabled Enable it on the Discord portal
Incorrect intents in the code Add GatewayIntentBits.MessageContent

The .env file is not read

❌ Cause ✅ Solution
dotenv not installed Check that it's in package.json
Incorrect require placement require('dotenv').config(); should be the first line
Incorrectly named file The file must be named exactly .env

npm install fails

❌ Error ✅ Solution
package.json not found Check that the file is at the root
ERESOLVE unable to resolve Update the versions in package.json

🔒 Security of the .env file

✅ To Do ❌ Not To Do
Keep the .env file only on the server Share the .env file
Create the .env file directly on OuiPanel Upload the .env file from your PC
Add .env to .gitignore Commit the .env file to GitHub

Recommended .gitignore file:

# Environment variables
.env

# Node modules
node_modules/

💡 Best Practices

Security

  • Never share your token
  • ✅ Create the .env file directly on the server
  • ✅ Regenerate the token if compromised

Performance

  • ✅ Only enable the necessary intents
  • ✅ Handle errors with try/catch
  • ✅ Add logs for debugging

📂 Advanced Structure (Recommended)

For a more organized bot:

📁 MyBot/
├── 📄 index.js              ← Entry point
├── 📄 package.json
├── 📄 .env                  ← Created on the server
├── 📁 commands/
│   ├── 📄 ping.js
│   ├── 📄 help.js
│   └── 📄 info.js
├── 📁 events/
│   ├── 📄 ready.js
│   └── 📄 messageCreate.js
└── 📄 config.json           ← Non-sensitive configuration

📝 Summary

1. Create the bot on Discord Developer Portal
2. Retrieve the Token and activate the Intents
3. Prepare the files (index.js + package.json with dotenv)
4. Upload the files to OuiPanel (without the .env)
5. Create the .env file on the server with the token
6. Configure the startup file (index.js, bot.js...)
7. Start the server
8. Verify that the bot is online on Discord