Corrects `self` parameter usage in command handlers See merge request pancakes1234/wdiscordbotserver!2
WDiscordBot
Last Updated: April 2025
Table of Contents
- [Introduction(
- [Understanding the Cog System
- [Directory Structure and Core Components
- [Guidelines for Modding Cogs
- [Files to Avoid Editing
- [Creating and Integrating New Cogs
- [Testing and Debugging Your Mods
- [Contributing
- [Conclusion
Introduction
WDiscordBot is an open-source bot designed for customization. This guide explains how to safely modify its features while preserving critical functionality.
Understanding the Cog System
The cog system enables modular bot functionality by separating commands, event listeners, and utilities into isolated components. Each cog has:
- Commands: Responds to user inputs.
- Listeners: Handles events like message triggers.
- Helpers/Utilities: Supports cog operations.
This separation makes the bot easy to maintain, scalable, and highly customizable.
Directory Structure and Core Components
The following is an overview of the files within the cogs
directory:
cogs
├── ai.py
├── application.py
├── automod.py
├── cog2.py
├── cogupdate.py
├── contribute.py
├── core.py
├── debug2.py
├── fun.py
├── howtohelp.py
├── issues.py
├── mod.py
├── rolemgt.py
├── roleplay.py
└── rule34.py
Key Notes:
-
Core Files:
core.py
cog2.py
debug2.py
cogupdate.py
These files should not be modified to ensure stability and functionality.
-
Customizable Files:
- Files like
mod.py
,automod.py
, androlemgt.py
are safe to edit for extending functionality.
- Files like
Guidelines for Modding Cogs
When modding WDiscordBot, follow these best practices:
-
Use Version Control:
- Always back up your changes using Git.
- Create separate branches for testing modifications.
-
Extend Rather Than Edit:
- Avoid modifying core files; extend functionality by creating new cogs or using inheritance.
-
Follow Coding Conventions:
- Use consistent naming, formatting, and documentation styles.
-
Error Handling:
- Implement robust error handling and log exceptions for easier debugging.
-
Keep Modifications Modular:
- Structure new features so they can be enabled or disabled independently.
Files to Avoid Editing
Do not modify the following files:
core.py
debug2.py
cog2.py
cogupdate.py
Why?
- Preserves Core Stability: These files are essential for WDiscordBot's base functionality.
- Ensures Easy Updates: Keeping these files untouched avoids compatibility issues during updates.
- Facilitates Collaboration: Contributors can focus on safe customization areas without worrying about breaking core features.
Creating and Integrating New Cogs
To safely add new features, create a new cog file. Below is a template for your custom cog:
# File: cogs/custommod.py
from discord.ext import commands
class CustomMod(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name="hello")
async def hello_command(self, ctx):
"""
Responds with a greeting message.
"""
await ctx.send("Hello, world!")
def setup(bot):
bot.add_cog(CustomMod(bot))
Steps:
-
Create the File: Place your new
.py
file in thecogs
directory. -
Register Your Cog: Ensure the bot loader (
main.py
) is set to register the new cog via thesetup
function. -
Test: Verify functionality locally before deploying changes.
Testing and Debugging Your Mods
Thorough testing ensures stable modifications. Follow these steps:
-
Use a Local Test Environment:
- Run WDiscordBot on a private server or test instance.
- Test all commands and listeners.
-
Write Unit and Integration Tests:
- Use mocks for simulating bot interactions.
-
Monitor Logs:
- Leverage the bot's logging system to debug exceptions or errors.
Contributing
We welcome contributions to WDiscordBot! Follow these steps to get started:
-
Fork the Repository:
- Click "Fork" on the GitHub page to create your own copy.
-
Clone Your Fork:
- Use
git clone <https://github.com/youruser/your-fork-name>
to download your fork locally.
- Use
-
Create a Branch:
- Always create a new branch for your changes using a descriptive name.
-
Implement Your Changes:
- Follow the coding guidelines and include necessary documentation and tests.
-
Submit a Pull Request:
- After testing locally, submit a pull request with a detailed description of your changes.
-
Participate in Code Review:
- Address feedback and update your branch as necessary.
-
Stay Synchronized:
- Regularly update your fork with changes from the upstream repository to avoid merge conflicts.
Need Help?
Join our Discord community or refer to the GitHub issue tracker for guidance.
Conclusion
Follow these best practices to keep WDiscordBot stable, mod-friendly, and collaborative. By avoiding modifications to core files, using modular design, and adhering to contribution guidelines, you'll foster a vibrant development community.