Skip to content

Commit 0f8d494

Browse files
committed
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
1 parent fe6c3b2 commit 0f8d494

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pydis_core/_bot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ def __init__(
9595
super().__init__(
9696
*args,
9797
allowed_roles=allowed_roles,
98+
tree_cls=CommandTreeBase,
9899
**kwargs,
99100
)
100101

102+
self.command_error_manager: CommandErrorManager | None = None
101103
self.guild_id = guild_id
102104
self.http_session = http_session
103105
self.api_client = api_client
@@ -119,6 +121,16 @@ def __init__(
119121

120122
self.all_extensions: frozenset[str] | None = None
121123

124+
def register_command_error_manager(self, manager: CommandErrorManager) -> None:
125+
"""
126+
Bind an instance of the command error manager to both the bot and the command tree.
127+
128+
The reason this doesn't happen in the constructor is because error handlers might need an instance of the bot.
129+
So registration needs to happen once the bot instance has been created.
130+
"""
131+
self.command_error_manager = manager
132+
self.tree.command_error_manager = manager
133+
122134
def _connect_statsd(
123135
self,
124136
statsd_url: str,

0 commit comments

Comments
 (0)