Game Servers & OuiPanelDecember 15, 2025 8 views

How to host a Discord bot (Python) on OuiPanel

How to host a Discord bot (Python) on OuiPanel

Hosting a Discord Bot (Python) on OuiPanel

Estimated Time: 15 minutes
Difficulty: Intermediate ⭐⭐
Server Type: Python


📋 Introduction

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

What You Need

Requirement 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 (bot.py, requirements.txt, etc.)
🐍 A Python server Ordered on OuiHeberg

🤖 Step 1: Create the Bot on Discord

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

Image

  1. Give a name to your application (e.g., "My Python Bot")
  2. Accept the terms of service
  3. Click on Create

Image


Get the Token

The token is the secret key that allows your code to connect to the bot.

  1. In the Bot section, find the TOKEN area
  2. Click on Reset Token
  3. Confirm by clicking on Yes, do it!
  4. Click on Copy to copy the tokenImage

⚠️ IMPORTANT - SECURITY :

  • The token is like a password. NEVER share it!
  • Never place it in public code (GitHub, GitLab, etc.)
  • If your token is compromised, regenerate it immediately
  • Keep it in a safe place for the next step

Enable Intents

Intents allow your bot to access certain information (messages, members, etc.).

  1. Still in the Bot section, scroll down to Privileged Gateway Intents
  2. Enable the necessary intents:
Intent Description Recommendation
PRESENCE INTENT See members' status Optional
SERVER MEMBERS INTENT Access the list of members Optional
MESSAGE CONTENT INTENT Read message content Required

Image

  1. Click on Save Changes

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


Invite the Bot to Your Discord Server

  1. In the left menu, click on OAuth2
  2. Click on URL GeneratorImage
  1. In the SCOPES section, check :
    • bot

  1. In the BOT PERMISSIONS section, check the necessary permissions:
Permission Description
Administrator All permissions (simple but broad)
OR specific permissions:
Send Messages Send messages
Read Message History Read history
Embed Links Send embeds
Attach Files Send files
Use Slash Commands Use slash commands

Image

  1. At the bottom of the page, copy the generated URL

Image

  1. Open this URL in your browser
  2. Select the server to invite the bot
  3. Click on Authorize
  4. Complete the captcha if prompted

Image

✅ Your bot now appears in the member list of your server (currently offline).


📁 Step 2: Prepare the Bot's Files

File Structure

Your bot must have this structure:

📁 MyPythonBot/
├── 📄 bot.py             ← Main file (or main.py, index.py...)
├── 📄 requirements.txt   ← Python dependencies
├── 📄 .env               ← Bot's token (created on the server)
└── 📁 cogs/              ← (Optional) Modules folder

requirements.txt File

Create a requirements.txt file with the dependencies discord.py and python-dotenv:

audioop-lts==0.2.1
discord.py==2.3.2
python-dotenv==1.0.0

💡 These two packages are essential:

  • discord.py: The library for interacting with Discord
  • python-dotenv: To load the token from the .env file

Main File (bot.py)

Create your main file with python-dotenv to load the token:

import os
import discord
from discord.ext import commands
from dotenv import load_dotenv

# Load environment variables from .env
load_dotenv()

# Intents configuration
intents = discord.Intents.default()
intents.message_content = True

# Bot creation with a prefix
bot = commands.Bot(command_prefix='!', intents=intents)

# Event: Bot ready
@bot.event
async def on_ready():
    print(f'✅ Bot connected as {bot.user.name}')
    print(f'📊 Connected to {len(bot.guilds)} server(s)')

# Command: !ping
@bot.command()
async def ping(ctx):
    """Responds Pong with latency"""
    latency = round(bot.latency * 1000)
    await ctx.send(f'🏓 Pong! Latency: {latency}ms')

# Command: !hello
@bot.command()
async def hello(ctx):
    """Says hello"""
    await ctx.send(f'👋 Hello {ctx.author.name}!')

# Error handling
@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        await ctx.send('❌ Unknown command.')
    else:
        print(f'Error: {error}')

# Connect with the token from .env
bot.run(os.getenv('DISCORD_TOKEN'))

⚠️ Important: load_dotenv() must be called before using os.getenv().


📤 Step 3: Upload Files to OuiPanel

Using the File Manager

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

Image

  1. Delete default files (if any)
  2. Click on Upload
  3. Upload your files:
    • bot.py (or main.py, index.py...)
    • requirements.txt
    • Your folders (cogs/...) if needed

Image

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


Using SFTP (Recommended for multiple files)

  1. Connect via SFTP with FileZilla
  2. Drag and drop all the content from 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

Image

  1. Replace your_token_here with the token copied in Step 1
  2. Click on Create or Save

Example with a real token (format):

DISCORD_TOKEN=MTIzNDU2Nzg5MDEyMzQ1Njc4OQ.ABcdEF.abcdefghijklmnopqrstuvwxyz123456

Example with multiple variables:

# Discord bot token
DISCORD_TOKEN=MTIzNDU2Nzg5MDEyMzQ1Njc4OQ.ABcdEF.abcdefghijklmnopqrstuvwxyz123456

# Command prefix
PREFIX=!

# Owner ID (optional)
OWNER_ID=123456789012345678

⚠️ Important:

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

Final Structure on the Server

📁 Root of the server/
├── 📄 .env               ← Contains DISCORD_TOKEN
├── 📄 bot.py             ← Your code
├── 📄 requirements.txt   ← Dependencies
└── ...

⚙️ Step 5: Configure the Startup File

OuiPanel needs to know which Python file to run at startup.

Accessing the settings

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

Image



Configuring the file to execute

Locate the File to execute field:

Image

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

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


🚀 Step 6: Start the Bot

Launching the server

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

Automatic installation of dependencies

On the first start, the server automatically installs packages from requirements.txt:

Installing requirements from requirements.txt...
Collecting discord.py==2.3.2
Collecting python-dotenv==1.0.0
Successfully installed discord.py-2.3.2 python-dotenv-1.0.0

Running bot.py...
✅ Bot connected as MyBot
📊 Connected to 1 server(s)

Image


✅ Step 7: Verify the Bot is Working

In the OuiPanel Console

You should see:

✅ Bot connected as MyBot
📊 Connected to 1 server(s)

On Discord

  1. Open Discord
  2. Go to the server where you invited the bot
  3. Your bot should appear online (green dot)
  4. Test a command: !ping
  5. The bot responds: 🏓 Pong! Latency: XXms

Image


🔧 Troubleshooting

The bot doesn't start

❌ Error ✅ Solution
ModuleNotFoundError: No module named 'discord' Check requirements.txt and restart
ModuleNotFoundError: No module named 'dotenv' Add python-dotenv to requirements.txt
FileNotFoundError: bot.py Incorrect startup file configured
SyntaxError Error in your Python code

Token Error

❌ Error ✅ Solution
LoginFailure: Improper token has been passed Check the token in .env
HTTPException: 401 Unauthorized Invalid token, regenerate it
PrivilegedIntentsRequired Enable intents on the Discord portal

Bot Not Reading Messages

❌ Cause ✅ Solution
MESSAGE CONTENT INTENT disabled Enable it on the Discord portal
Intents misconfigured in the code Add intents.message_content = True

Check your code:

intents = discord.Intents.default()
intents.message_content = True  # This line is mandatory!

.env File Not Being Read

❌ Cause ✅ Solution
python-dotenv not installed Check requirements.txt
load_dotenv() not called Add load_dotenv() before os.getenv()
Incorrectly named file The file must be named exactly .env
Incorrect format No spaces around the =

pip install Fails

❌ Error ✅ Solution
requirements.txt not found Ensure the file is at the root
Could not find a version Check package names and versions

🔒 Securing 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 Put the token in the code
Add .env to .gitignore Commit the .env to GitHub

Recommended .gitignore file:

# Environment variables
.env
.env.local

# Python
__pycache__/
*.py[cod]
venv/

💡 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
  • ✅ Use commands.Bot instead of discord.Client for commands
  • ✅ Use Cogs to organize your code

Code

  • ✅ Handle errors with try/except
  • ✅ Add logs with print() or the logging module
  • ✅ Use Cogs for large bots

📂 Advanced Structure with Cogs (Recommended)

For a more organized bot:

📁 MyPythonBot/
├── 📄 bot.py               ← Entry point
├── 📄 requirements.txt
├── 📄 .env                 ← Created on the server
├── 📁 cogs/
│   ├── 📄 moderation.py    ← Moderation commands
│   ├── 📄 fun.py           ← Fun commands
│   └── 📄 utility.py       ← Utility commands
└── 📄 config.py            ← Non-sensitive configuration

Example of bot.py with Cogs:

import os
import discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)

# Load cogs on startup
@bot.event
async def on_ready():
    print(f'✅ Bot connected as {bot.user.name}')
    
    # Load cogs
    for filename in os.listdir('./cogs'):
        if filename.endswith('.py'):
            await bot.load_extension(f'cogs.{filename[:-3]}')
            print(f'📦 Cog loaded: {filename}')

bot.run(os.getenv('DISCORD_TOKEN'))

Example of a cog (cogs/fun.py):

import discord
from discord.ext import commands

class Fun(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
    
    @commands.command()
    async def ping(self, ctx):
        """Responds Pong!"""
        latency = round(self.bot.latency * 1000)
        await ctx.send(f'🏓 Pong! Latency: {latency}ms')
    
    @commands.command()
    async def hello(self, ctx):
        """Says hello"""
        await ctx.send(f'👋 Hello {ctx.author.name}!')

async def setup(bot):
    await bot.add_cog(Fun(bot))

📝 Summary

1. Create the bot on Discord Developer Portal
2. Get the Token (Reset Token → Copy)
3. Enable MESSAGE CONTENT INTENT
4. Invite the bot (OAuth2 → URL Generator → bot + applications.commands)
5. Prepare files (bot.py + requirements.txt with python-dotenv)
6. Upload files to OuiPanel (without the .env)
7. Create the .env file on the server with the token
8. Configure the startup file (bot.py, main.py...)
9. Start the server
10. Check that the bot is online on Discord → !ping