A Python-based Discord bot framework with hot-reloading and MongoDB support
Project description
PyDiscoBasePro
A Python-based Discord bot framework inspired by Discobase, with advanced features for building scalable Discord bots.
Features
- Prefix-based commands with aliases and cooldowns
- Slash commands with auto-registration
- Context menus support
- Dynamic loading/unloading of commands, events, and components
- Hot-reloading without restarting the bot
- Permission checks (roles, users, admin, bot permissions)
- Error logging, crash reporting, and recovery
- Event hooks for various Discord events
- Optional web dashboard for bot stats
- Persistent storage with MongoDB
- Configurable via JSON
- Logging to files and Discord channels
- Automatic command help generation
- Support for embeds, buttons, selects, modals
- Built-in utilities (timers, randomizers, cooldown helpers, API helpers)
- Easy extension system for plugins
Installation
Option 1: Manual Setup
-
Clone the repository:
git clone https://github.com/yourusername/pydiscobasepro.git cd pydiscobasepro
-
Install dependencies:
pip install -r requirements.txt
-
Set up MongoDB (local or cloud instance).
-
Configure
config/config.jsonwith your bot token and settings. -
Run the bot:
python bot.py
Option 2: Use CLI Generator
-
Install the framework globally (optional):
pip install -e .
-
Generate a new project:
python cli.py create MyBotProject # or if installed: pydisco create MyBotProject
-
Navigate to the project:
cd MyBotProject pip install -r requirements.txt
-
Configure and run as above.
Configuration
Edit config/config.json:
{
"token": "YOUR_BOT_TOKEN",
"prefix": "!",
"intents": {
"guilds": true,
"members": true,
"messages": true,
"message_content": true,
"voice_states": true,
"reactions": true
},
"mongodb": {
"uri": "mongodb://localhost:27017",
"database": "pydiscobasepro"
},
"logging": {
"level": "INFO",
"file": "logs/bot.log",
"discord_channel_id": null
},
"dashboard": {
"enabled": false,
"host": "0.0.0.0",
"port": 8080
}
}
Usage
Creating Commands
Create a new file in commands/ directory. Example: commands/ping.py
import discord
from discord import app_commands
from discord.ext import commands
class Ping:
def __init__(self, bot, database):
self.bot = bot
self.database = database
self.name = "ping"
self.description = "Check bot latency"
self.aliases = ["pong"]
self.permissions = []
self.cooldown = 5
self.prefix_command = commands.command(name=self.name, aliases=self.aliases, help=self.description)(
self.run_prefix
)
self.slash_command = app_commands.Command(
name=self.name,
description=self.description,
callback=self.run_slash
)
async def run_prefix(self, ctx):
latency = round(self.bot.latency * 1000)
embed = discord.Embed(title="Pong!", description=f"Latency: {latency}ms", color=0x00ff00)
await ctx.send(embed=embed)
async def run_slash(self, interaction: discord.Interaction):
latency = round(self.bot.latency * 1000)
embed = discord.Embed(title="Pong!", description=f"Latency: {latency}ms", color=0x00ff00)
await interaction.response.send_message(embed=embed)
Creating Events
Create in events/ directory. Example: events/on_ready.py
import discord
from loguru import logger
class OnReady:
def __init__(self, bot, database):
self.bot = bot
self.database = database
@self.bot.event
async def on_ready():
logger.info("Bot is ready!")
Creating Components
Create in components/ directory. Example: components/test_button.py
import discord
from discord.ui import Button, View
class TestButton:
def __init__(self, bot, database):
self.bot = bot
self.database = database
@self.bot.event
async def on_interaction(interaction: discord.Interaction):
if interaction.type == discord.InteractionType.component:
if interaction.custom_id == "test_button":
await interaction.response.send_message("Button clicked!", ephemeral=True)
Dashboard
If enabled in config, access at http://localhost:8080 for basic stats.
MongoDB Integration
The framework uses MongoDB for persistent storage. Example usage:
# In a command
guild_config = await self.database.get_guild_config(ctx.guild.id)
if not guild_config:
guild_config = GuildConfig(ctx.guild.id)
await self.database.update_guild_config(guild_config)
user_profile = await self.database.get_user_profile(ctx.author.id)
user_profile.xp += 10
await self.database.update_user_profile(user_profile)
# Track command usage
await self.database.increment_command_usage("ping")
Production Deployment
- Use a process manager like PM2 or systemd
- Set up environment variables for sensitive data
- Configure MongoDB for production
- Enable dashboard for monitoring
Contributing
- Fork the repository
- Create a feature branch
- Make changes
- Submit a pull request
Credits
- Original Inspiration: Code-X organization
- Lead Developer: Ramkrishna
- Co-developer: Razzak
License
MIT License - see LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydiscobasepro-1.0.0.tar.gz.
File metadata
- Download URL: pydiscobasepro-1.0.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a44fbcfa9840794e26982903b85c0093cd46f3d262fbc744db84e2e34521be37
|
|
| MD5 |
4b1169941558ac0896fcd6b5836e9d59
|
|
| BLAKE2b-256 |
5e95b480e529b85b1ca7abd49c668307bef3a75ec1a53f664c4135b6303f13a4
|
File details
Details for the file pydiscobasepro-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pydiscobasepro-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
238f448160ae7d29f414a11d26a351a4445591d514e2e025386f337dbf1a39dd
|
|
| MD5 |
c857adcf6597589d9d643295cafdd703
|
|
| BLAKE2b-256 |
39f19b4e4f1087f134fb103e7bf2e0bce27bd22d74df68e7eb02fd6cca9a6f48
|