Skip to content

Commit 1585043

Browse files
committed
Implemented #51 suggestion
1 parent 9a595be commit 1585043

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

discord_slash/client.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class SlashCommand:
2222
:type sync_commands: bool
2323
:param delete_from_unused_guilds: If the bot should make a request to set no commands for guilds that haven't got any commands registered in :class:``SlashCommand``. Default `False`.
2424
:type delete_from_unused_guilds: bool
25-
:param sync_on_cog_edit: Whether to sync commands on cog load/unload/reload. Default `False`.
26-
:type sync_on_cog_edit: bool
25+
:param sync_on_cog_reload: Whether to sync commands on cog reload. Default `False`.
26+
:type sync_on_cog_reload: bool
2727
:param override_type: Whether to override checking type of the client and try register event.
2828
:type override_type: bool
2929
@@ -32,23 +32,23 @@ class SlashCommand:
3232
:ivar req: :class:`.http.SlashCommandRequest` of this client.
3333
:ivar logger: Logger of this client.
3434
:ivar sync_commands: Whether to sync commands automatically.
35-
:ivar sync_on_cog_edit: Whether to sync commands on cog load/unload/reload.
35+
:ivar sync_on_cog_reload: Whether to sync commands on cog reload.
3636
:ivar has_listener: Whether discord client has listener add function.
3737
"""
3838

3939
def __init__(self,
4040
client: typing.Union[discord.Client, commands.Bot],
4141
sync_commands: bool = False,
4242
delete_from_unused_guilds: bool = False,
43-
sync_on_cog_edit: bool = False,
43+
sync_on_cog_reload: bool = False,
4444
override_type: bool = False):
4545
self._discord = client
4646
self.commands = {}
4747
self.subcommands = {}
4848
self.logger = logging.getLogger("discord_slash")
4949
self.req = http.SlashCommandRequest(self.logger, self._discord)
5050
self.sync_commands = sync_commands
51-
self.sync_on_cog_edit = sync_on_cog_edit
51+
self.sync_on_cog_reload = sync_on_cog_reload
5252

5353
if self.sync_commands:
5454
self._discord.loop.create_task(self.sync_all_commands(delete_from_unused_guilds))
@@ -89,6 +89,15 @@ def override_remove_cog(name: str):
8989

9090
self._discord.remove_cog = override_remove_cog
9191

92+
if self.sync_on_cog_reload:
93+
orig_reload = self._discord.reload_extension
94+
95+
def override_reload_extension(*args):
96+
orig_reload(*args)
97+
self._discord.loop.create_task(self.sync_all_commands(delete_from_unused_guilds))
98+
99+
self._discord.reload_extension = override_reload_extension
100+
92101
def get_cog_commands(self, cog: commands.Cog):
93102
"""
94103
Gets slash command from :class:`discord.ext.commands.Cog`.

0 commit comments

Comments
 (0)