@@ -49,7 +49,7 @@ def __init__(self,
4949 self ._discord .loop .create_task (self .register_all_commands ())
5050 elif self .auto_delete :
5151 self ._discord .loop .create_task (self .delete_unused_commands ())
52-
52+
5353 if not isinstance (client , commands .Bot ) and not isinstance (client ,
5454 commands .AutoShardedBot ) and not override_type :
5555 self .logger .info ("Detected discord.Client! Overriding on_socket_response." )
@@ -60,21 +60,25 @@ def __init__(self,
6060 self ._discord .slash = self
6161 else :
6262 raise error .DuplicateSlashClient ("You can't have duplicate SlashCommand instances!" )
63-
63+
6464 self ._discord .add_listener (self .on_socket_response )
6565 self .has_listener = True
6666 default_add_function = self ._discord .add_cog
67+
6768 def override_add_cog (cog : commands .Cog ):
6869 default_add_function (cog )
6970 self .get_cog_commands (cog )
71+
7072 self ._discord .add_cog = override_add_cog
7173 default_remove_function = self ._discord .remove_cog
74+
7275 def override_remove_cog (name : str ):
7376 cog = self ._discord .get_cog (name )
7477 if cog is None :
7578 return
7679 self .remove_cog_commands (cog )
7780 default_remove_function (name )
81+
7882 self ._discord .remove_cog = override_remove_cog
7983
8084 def get_cog_commands (self , cog : commands .Cog ):
@@ -87,10 +91,10 @@ def get_cog_commands(self, cog: commands.Cog):
8791 :param cog: Cog that has slash commands.
8892 :type cog: discord.ext.commands.Cog
8993 """
90- if hasattr (cog , '_slash_registered' ): # Temporary warning
94+ if hasattr (cog , '_slash_registered' ): # Temporary warning
9195 return self .logger .warning ("Calling get_cog_commands is no longer required "
9296 "to add cog slash commands. Make sure to remove all calls to this function." )
93- cog ._slash_registered = True # Assuming all went well
97+ cog ._slash_registered = True # Assuming all went well
9498 func_list = [getattr (cog , x ) for x in dir (cog )]
9599 res = [x for x in func_list if isinstance (x , (model .CogCommandObject , model .CogSubcommandObject ))]
96100 for x in res :
@@ -197,7 +201,7 @@ async def to_dict(self):
197201 # so we will warn this at registering subcommands.
198202 self .logger .warning (f"Detected command name with same subcommand base name! "
199203 f"This command will only have subcommand: { x } " )
200-
204+
201205 options = []
202206 if selected .has_subcommands :
203207 tgt = self .subcommands [x ]
@@ -247,7 +251,7 @@ async def to_dict(self):
247251
248252 return commands
249253
250- async def sync_all_commands (self , delete_from_unused_guilds = True ):
254+ async def sync_all_commands (self , delete_from_unused_guilds = True ):
251255 """
252256 Matches commands registered on Discord to commands registered here.
253257 Deletes any commands on Discord but not here, and registers any not on Discord.
@@ -262,15 +266,15 @@ async def sync_all_commands(self, delete_from_unused_guilds = True):
262266 # This is an extremly bad way to do this, because slash cmds can be in guilds the bot isn't in
263267 # But it's the only way until discord makes an endpoint to request all the guild with cmds registered.
264268
265- await self .req .put_slash_commands (slash_commands = commands ["global" ], guild_id = None )
266-
269+ await self .req .put_slash_commands (slash_commands = commands ["global" ], guild_id = None )
270+
267271 for guild in commands ["guild" ]:
268- await self .req .put_slash_commands (slash_commands = commands ["guild" ][guild ], guild_id = guild )
272+ await self .req .put_slash_commands (slash_commands = commands ["guild" ][guild ], guild_id = guild )
269273 all_bot_guilds .remove (guild )
270274 if delete_from_unused_guilds :
271275 for guild in all_bot_guilds :
272- await self .req .put_slash_commands (slash_commands = [], guild_id = guild )
273-
276+ await self .req .put_slash_commands (slash_commands = [], guild_id = guild )
277+
274278 self .logger .info ("Completed syncing all commands!" )
275279
276280 async def register_all_commands (self ):
@@ -283,14 +287,14 @@ async def register_all_commands(self):
283287 for command in commands ["global" ]:
284288 name = command .pop ('name' )
285289 self .logger .debug (f"Registering global command { name } " )
286- await self .req .add_slash_command (guild_id = None , cmd_name = name , ** command )
287-
290+ await self .req .add_slash_command (guild_id = None , cmd_name = name , ** command )
291+
288292 for guild in commands ["guild" ]:
289293 guild_cmds = commands ["guild" ][guild ]
290294 for command in guild_cmds :
291295 name = command .pop ('name' )
292296 self .logger .debug (f"Registering guild command { name } in guild: { guild } " )
293- await self .req .add_slash_command (guild_id = guild , cmd_name = name , ** command )
297+ await self .req .add_slash_command (guild_id = guild , cmd_name = name , ** command )
294298 self .logger .info ("Completed registering all commands!" )
295299
296300 async def delete_unused_commands (self ):
@@ -660,12 +664,12 @@ async def process_options(self, guild: discord.Guild, options: list, auto_conver
660664 for x in options :
661665 selected = x
662666 if selected ["name" ] in auto_convert :
663- processed = None # This isn't the best way, but we should to reduce duplicate lines.
667+ processed = None # This isn't the best way, but we should to reduce duplicate lines.
664668 if auto_convert [selected ["name" ]] not in types :
665669 processed = selected ["value" ]
666670 else :
667671 loaded_converter = converters [types [auto_convert [selected ["name" ]]]]
668- if isinstance (loaded_converter , list ): # For user type.
672+ if isinstance (loaded_converter , list ): # For user type.
669673 cache_first = loaded_converter [0 ](int (selected ["value" ]))
670674 if cache_first :
671675 processed = cache_first
@@ -676,7 +680,7 @@ async def process_options(self, guild: discord.Guild, options: list, auto_conver
676680 processed = await loaded_converter (int (selected ["value" ])) \
677681 if iscoroutinefunction (loaded_converter ) else \
678682 loaded_converter (int (selected ["value" ]))
679- except (discord .Forbidden , discord .HTTPException , discord .NotFound ): # Just in case.
683+ except (discord .Forbidden , discord .HTTPException , discord .NotFound ): # Just in case.
680684 self .logger .warning ("Failed fetching discord object! Passing ID instead." )
681685 processed = int (selected ["value" ])
682686 to_return [selected ["name" ]] = processed
0 commit comments