Skip to content

Commit 6830e51

Browse files
committed
Added more options to SlashCommand
1 parent 02d1e34 commit 6830e51

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

discord_slash/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
class SlashCommand:
1616
"""
17-
Slash command extension class.
17+
Slash command handler class.
1818
1919
:param client: discord.py Client or Bot instance.
2020
:type client: Union[discord.Client, discord.ext.commands.Bot]
2121
:param sync_commands: Whether to sync commands automatically. Default `False`.
2222
:type sync_commands: bool
23+
: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`.
24+
: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
2327
:param override_type: Whether to override checking type of the client and try register event.
2428
:type override_type: bool
2529
@@ -28,22 +32,26 @@ class SlashCommand:
2832
:ivar req: :class:`.http.SlashCommandRequest` of this client.
2933
:ivar logger: Logger of this client.
3034
:ivar sync_commands: Whether to sync commands automatically.
35+
:ivar sync_on_cog_edit: Whether to sync commands on cog load/unload/reload.
3136
:ivar has_listener: Whether discord client has listener add function.
3237
"""
3338

3439
def __init__(self,
3540
client: typing.Union[discord.Client, commands.Bot],
3641
sync_commands: bool = False,
42+
delete_from_unused_guilds: bool = False,
43+
sync_on_cog_edit: bool = False,
3744
override_type: bool = False):
3845
self._discord = client
3946
self.commands = {}
4047
self.subcommands = {}
4148
self.logger = logging.getLogger("discord_slash")
4249
self.req = http.SlashCommandRequest(self.logger, self._discord)
4350
self.sync_commands = sync_commands
51+
self.sync_on_cog_edit = sync_on_cog_edit
4452

4553
if self.sync_commands:
46-
self._discord.loop.create_task(self.sync_all_commands())
54+
self._discord.loop.create_task(self.sync_all_commands(delete_from_unused_guilds))
4755

4856
if not isinstance(client, commands.Bot) and not isinstance(client, commands.AutoShardedBot) and not override_type:
4957
self.logger.info("Detected discord.Client! It is highly recommended to use `commands.Bot`.")

discord_slash/error.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class CheckFailure(SlashCommandError):
4949
Command check has failed.
5050
"""
5151

52+
5253
class IncorrectType(SlashCommandError):
5354
"""
5455
Type passed was incorrect

0 commit comments

Comments
 (0)