Skip to content

Commit 94ba404

Browse files
Add cog_load and cog_unload method (#34)
* Add `cog_load` and `cog_unload` method * Move `cog_load` to end * Resolve conflict
1 parent 4002be8 commit 94ba404

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

docs/ext/commands/api.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Command
1919
.. autoclass:: revolt.ext.commands.Command
2020
:members:
2121

22+
Cog
23+
~~~~
24+
.. autoclass:: revolt.ext.commands.Cog
25+
:members:
26+
2227
command
2328
~~~~~~~~
2429
.. autodecorator:: revolt.ext.commands.command

revolt/ext/commands/cog.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,30 @@ class Cog(metaclass=CogMeta):
3232
_commands: list[Command]
3333
qualified_name: str
3434

35-
def _inject(self, client: CommandsClient):
35+
def cog_load(self):
36+
"""A special method that is called when the cog gets loaded."""
37+
pass
38+
39+
def cog_unload(self):
40+
"""A special method that is called when the cog gets removed."""
41+
pass
42+
43+
def _inject(self, client: CommandsClient):
3644
client.cogs[self.qualified_name] = self
3745

3846
for command in self._commands:
3947
command.cog = self
4048
client.add_command(command)
4149

50+
self.cog_load()
51+
4252
def _uninject(self, client: CommandsClient):
4353
for name, command in client.all_commands.copy().items():
4454
if command in self._commands:
4555
del client.all_commands[name]
4656

57+
self.cog_unload()
58+
4759
@property
4860
def commands(self) -> list[Command]:
4961
return self._commands

0 commit comments

Comments
 (0)