API: handlers¶
handlers.moduleHandler
¶
ModuleHandler
¶
Discover, initialize, and manage feature modules.
Scans the ./modules
directory, reads each module's manifest.json
, executes the
module's initFile
(usually main.py
) and wires exported commands, events,
interface hooks and settings into the running bot.
Source code in handlers/moduleHandler.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
__init__(bot, logger)
¶
Initialize the handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bot
|
ExtendedClient
|
The extended Discord client. |
required |
logger
|
Logger
|
Logger used for diagnostics. |
required |
Source code in handlers/moduleHandler.py
20 21 22 23 24 25 26 27 28 29 30 |
|
load_modules(specific_module=None)
async
¶
Load modules from disk and attach their commands/events.
Walks self.modules_path
, reads each manifest.json
, executes the module
setup file, builds a :class:Module
instance and delegates:
- commands to CommandHandler.load_commands_from_folder
- events to EventHandler.load_events_from_module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
specific_module
|
Optional[str]
|
If provided, load only that folder name; otherwise load all. |
None
|
Source code in handlers/moduleHandler.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
register_permissions(module_name, permissions)
¶
Register a list of permission nodes on behalf of a module.
Note
This implementation registers nodes that always resolve to True
.
Replace the lambda with proper checks (or namespace handlers) if your
modules rely on real permission enforcement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
str
|
Name of the module requesting the nodes. |
required |
permissions
|
List[str]
|
Permission paths (e.g., "Feature.Admin.Purge", "Role.*"). |
required |
Source code in handlers/moduleHandler.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
reload_modules()
async
¶
Reload all modules by unloading then loading them again.
Useful during development or when hot‑reloading code on disk.
Source code in handlers/moduleHandler.py
206 207 208 209 210 211 212 |
|
unload_modules()
async
¶
Unload all modules that were previously loaded.
Calls each module's unload(bot)
coroutine (if implemented), removes it
from the in‑memory registry, and logs results.
Source code in handlers/moduleHandler.py
192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
handlers.commandHandler
¶
CommandHandler
¶
Central registry and loader for module commands.
Dynamically imports command files, collects exported objects, and registers: - Slash commands / groups into the app command tree - Prefix commands into the bot - Cogs (async add + bookkeeping) - Detailed help entries - Deferred Subcommand attachments (processed later)
Source code in handlers/commandHandler.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
__init__(bot, logger)
¶
Initialize the handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bot
|
Bot
|
Discord.py bot (or ExtendedClient). |
required |
logger
|
Logger
|
Logger used for diagnostics. |
required |
Source code in handlers/commandHandler.py
25 26 27 28 29 30 31 32 33 34 35 |
|
load_commands_from_folder(folder, base_package, module)
async
¶
Import and register all command files found under a folder.
Recursively walks folder
, imports each .py
file as a module under
base_package
, then processes its exports
iterable (if present).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder
|
Path
|
Directory containing command files. |
required |
base_package
|
str
|
Python package prefix to assign to imports (e.g. "modules.foo.commands"). |
required |
module
|
Module
|
The owning :class: |
required |
Source code in handlers/commandHandler.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
process_export(export, module)
async
¶
Process a single exported symbol from a command file.
Supported export types
app_commands.Command
/app_commands.Group
→ slash registrationcommands.Command
→ prefix command registrationcommands.Cog
instance → async add, track commandsCommandHelp
→ stored inbot.detailed_help
Subcommand
→ queued and attached byprocess_pending_subcommands
- A class with
async def setup(bot)
→ invoked - A subclass of
commands.Cog
withoutsetup
→ instantiated and added
Parameters:
Name | Type | Description | Default |
---|---|---|---|
export
|
Any
|
The exported object to register. |
required |
module
|
Module
|
The owning module. |
required |
Source code in handlers/commandHandler.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
process_pending_subcommands()
¶
Attach queued subcommands to their parent groups.
If a parent group is missing, creates it automatically and adds it to
the app command tree. Updates module.commands["slash"]
accordingly.
Source code in handlers/commandHandler.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
register_regular_command(command, module)
¶
Register a text (prefix) command into the bot.
Also records the command under module.commands["text"]
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command
|
Command
|
The command object to add via |
required |
module
|
Module
|
The owning module used for bookkeeping. |
required |
Source code in handlers/commandHandler.py
153 154 155 156 157 158 159 160 161 162 163 164 |
|
register_slash_command(command, module)
¶
Register a slash command or group into the bot's command tree.
Also records the command under module.commands["slash"]
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command
|
Command | Group
|
The slash command or group to add. |
required |
module
|
Module
|
The owning module used for bookkeeping. |
required |
Source code in handlers/commandHandler.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
register_subcommand(subcommand, module)
¶
Queue a Subcommand
for attachment to its parent group.
If the parent group does not yet exist, the subcommand is queued until
process_pending_subcommands()
creates or finds the parent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subcommand
|
Subcommand
|
The subcommand descriptor. |
required |
module
|
Module
|
The owning module used for bookkeeping. |
required |
Source code in handlers/commandHandler.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
handlers.eventHandler
¶
EventHandler
¶
Dynamic loader/registrar for module events.
Imports Python files from each module's events
folder and registers exported
event listeners on the bot using bot.add_listener
.
Source code in handlers/eventHandler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
__init__(bot, logger)
¶
Initialize the handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bot
|
Bot
|
Discord.py bot (or ExtendedClient). |
required |
logger
|
Logger
|
Logger used for diagnostics. |
required |
Source code in handlers/eventHandler.py
17 18 19 20 21 22 23 24 25 |
|
load_events_from_module(module_name, events_path, module)
¶
Import and register event listeners from a module's events
directory.
Each event file may expose an exports
list of dicts with keys:
- "event": Discord.py event name (e.g., "on_message")
- "func": callable listener to be registered via bot.add_listener
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
str
|
Module's folder name (used to build import name). |
required |
events_path
|
Path
|
Path to the module's events directory. |
required |
module
|
Module
|
The owning :class: |
required |
Source code in handlers/eventHandler.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|