diff options
author | 2024-02-18 20:00:25 +0100 | |
---|---|---|
committer | 2024-03-18 11:37:57 +0100 | |
commit | 0f8d49428a0e048b9b460f235fbe36d6be10d05f (patch) | |
tree | 14bbaa5b5fd75d286900922a004e37c8a8f43155 /pydis_core/_bot.py | |
parent | subclass CommandTree (diff) |
expose a way for registering the command error manager
The manager instance needs to be bound "late" due to the bot since error handlers might need an instance of bot to work
Diffstat (limited to 'pydis_core/_bot.py')
-rw-r--r-- | pydis_core/_bot.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/pydis_core/_bot.py b/pydis_core/_bot.py index 08dca6a4..783715dd 100644 --- a/pydis_core/_bot.py +++ b/pydis_core/_bot.py @@ -95,9 +95,11 @@ class BotBase(commands.Bot): super().__init__( *args, allowed_roles=allowed_roles, + tree_cls=CommandTreeBase, **kwargs, ) + self.command_error_manager: CommandErrorManager | None = None self.guild_id = guild_id self.http_session = http_session self.api_client = api_client @@ -119,6 +121,16 @@ class BotBase(commands.Bot): self.all_extensions: frozenset[str] | None = None + def register_command_error_manager(self, manager: CommandErrorManager) -> None: + """ + Bind an instance of the command error manager to both the bot and the command tree. + + The reason this doesn't happen in the constructor is because error handlers might need an instance of the bot. + So registration needs to happen once the bot instance has been created. + """ + self.command_error_manager = manager + self.tree.command_error_manager = manager + def _connect_statsd( self, statsd_url: str, |