From 0f8d49428a0e048b9b460f235fbe36d6be10d05f Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sun, 18 Feb 2024 20:00:25 +0100 Subject: 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 --- pydis_core/_bot.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'pydis_core') 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, -- cgit v1.2.3