cogs/, shared utilities live in utils/, and a single registry file (utils/modules.py) controls what’s available at runtime. Add a file, register it, and enable it from Discord — no restart required.
How Modules Work
- Each feature lives in
cogs/<category>/<name>.pyas a discord.pyCogclass. - Core modules (
help,ping,status,admin) always load on startup and cannot be toggled. - Optional modules are registered in
OPTIONAL_MODULESinutils/modules.pyand can be toggled via/module enableand/module disableat runtime. - Enabled/disabled state persists in
config.jsonunderenabled_modules, so your configuration survives restarts. - Slash commands are automatically re-synced when you enable or disable a module.
Creating a New Module
Create the cog file
Create Place it under an existing category (
cogs/<category>/<name>.py. At minimum, define a Cog subclass and a setup coroutine:cogs/tools/mycommand.py
ai, media, moderation, system, tools, fun) or create a new subfolder.Register it in utils/modules.py
Add an entry to Once registered, the key appears in
OPTIONAL_MODULES using a short lowercase key and the full dotted module path:utils/modules.py
/module list and supports autocomplete.Enable it from Discord
Run the enable command in your server:The bot loads the cog immediately and re-syncs slash commands.
Accessing Bot Utilities
Import fromutils/ for functionality shared across cogs:
| Module | What it provides |
|---|---|
utils/generation.py | safe_generate — the main AI generation call with security checks, persona injection, and memory injection |
utils/memory.py | get_user_facts_prompt, extract_and_store_fact — read and write per-user long-term facts |
utils/persona.py | assemble_persona — build the active system instruction from the current persona fields |
utils/config.py | load_config, save_config — read and write config.json at runtime |
utils/security.py | detect_injection, sanitize_prompt, is_public_http_url — input validation and URL guards |
utils/rss.py | load_rss_feeds, parse_feed, save_rss_feed — RSS/Atom feed management |
Adding Slash Command Support
discord.py supports exposing a single command as both a prefix and a slash command via@commands.hybrid_command. Use this by default — one decorator, one callback:
@app_commands.command and @commands.command callbacks when the slash version needs interaction-only features that @commands.command can’t provide — for example, modals (interaction.response.send_modal(...)), which require a raw discord.Interaction.
After adding new slash commands, run /sync (Bot Owner) to register them globally with Discord. The /module enable and /module disable commands also trigger an automatic re-sync.
Run
python scripts/check_project.py before deploying to verify syntax and config. On Windows PowerShell you can use .\\scripts\\check.ps1 instead. Both run the same checks and exit non-zero on any failure.