diff --git a/docs/ext/commands/api.rst b/docs/ext/commands/api.rst index b7b8d51..1f473a0 100755 --- a/docs/ext/commands/api.rst +++ b/docs/ext/commands/api.rst @@ -19,6 +19,11 @@ Command .. autoclass:: revolt.ext.commands.Command :members: +Cog +~~~~ +.. autoclass:: revolt.ext.commands.Cog + :members: + command ~~~~~~~~ .. autodecorator:: revolt.ext.commands.command diff --git a/revolt/ext/commands/cog.py b/revolt/ext/commands/cog.py index 70f5854..02a229c 100755 --- a/revolt/ext/commands/cog.py +++ b/revolt/ext/commands/cog.py @@ -32,18 +32,30 @@ class Cog(metaclass=CogMeta): _commands: list[Command] qualified_name: str - def _inject(self, client: CommandsClient): + def cog_load(self): + """A special method that is called when the cog gets loaded.""" + pass + + def cog_unload(self): + """A special method that is called when the cog gets removed.""" + pass + + def _inject(self, client: CommandsClient): client.cogs[self.qualified_name] = self for command in self._commands: command.cog = self client.add_command(command) + self.cog_load() + def _uninject(self, client: CommandsClient): for name, command in client.all_commands.copy().items(): if command in self._commands: del client.all_commands[name] + self.cog_unload() + @property def commands(self) -> list[Command]: return self._commands