def get_cog_commands(self, cog: commands.Cog): """ Gets slash command from :class:`discord.ext.commands.Cog`. .. note:: Since version ``1.0.9``, this gets called automatically during cog initialization. :param cog: Cog that has slash commands. :type cog: discord.ext.commands.Cog """ if hasattr(cog, '_slash_registered'): # Temporary warning return self.logger.warning( "Calling get_cog_commands is no longer required " "to add cog slash commands. Make sure to remove all calls to this function." ) cog._slash_registered = True # Assuming all went well func_list = [getattr(cog, x) for x in dir(cog)] res = [ x for x in func_list if isinstance(x, (model.CogBaseCommandObject, model.CogSubcommandObject)) ] for x in res: x.cog = cog if isinstance(x, model.CogBaseCommandObject): if x.name in self.commands: raise error.DuplicateCommand(x.name) self.commands[x.name] = x else: if x.base in self.commands: base_command = self.commands[x.base] for i in x.allowed_guild_ids: if i not in base_command.allowed_guild_ids: base_command.allowed_guild_ids.append(i) base_permissions = x.base_command_data["api_permissions"] if base_permissions: for applicable_guild in base_permissions: if applicable_guild not in base_command.permissions: base_command.permissions[applicable_guild] = [] base_command.permissions[applicable_guild].extend( base_permissions[applicable_guild]) self.commands[x.base].has_subcommands = True else: self.commands[x.base] = model.BaseCommandObject( x.base, x.base_command_data) if x.base not in self.subcommands: self.subcommands[x.base] = {} if x.subcommand_group: if x.subcommand_group not in self.subcommands[x.base]: self.subcommands[x.base][x.subcommand_group] = {} if x.name in self.subcommands[x.base][x.subcommand_group]: raise error.DuplicateCommand( f"{x.base} {x.subcommand_group} {x.name}") self.subcommands[x.base][x.subcommand_group][x.name] = x else: if x.name in self.subcommands[x.base]: raise error.DuplicateCommand(f"{x.base} {x.name}") self.subcommands[x.base][x.name] = x
def get_cog_commands(self, cog: commands.Cog): """ Gets slash command from :class:`discord.ext.commands.Cog`. .. note:: Since version ``1.0.9``, this gets called automatically during cog initialization. :param cog: Cog that has slash commands. :type cog: discord.ext.commands.Cog """ if hasattr(cog, "_slash_registered"): # Temporary warning return self.logger.warning( "Calling get_cog_commands is no longer required " "to add cog slash commands. Make sure to remove all calls to this function." ) cog._slash_registered = True # Assuming all went well func_list = [getattr(cog, x) for x in dir(cog)] res = [ x for x in func_list if isinstance(x, (model.CogCommandObject, model.CogSubcommandObject)) ] for x in res: x.cog = cog if isinstance(x, model.CogCommandObject): if x.name in self.commands: raise error.DuplicateCommand(x.name) self.commands[x.name] = x else: if x.base in self.commands: for i in x.allowed_guild_ids: if i not in self.commands[x.base].allowed_guild_ids: self.commands[x.base].allowed_guild_ids.append(i) self.commands[x.base].has_subcommands = True else: _cmd = { "func": None, "description": x.base_description, "auto_convert": {}, "guild_ids": x.allowed_guild_ids.copy(), "api_options": [], "has_subcommands": True, "connector": {}, } self.commands[x.base] = model.CommandObject(x.base, _cmd) if x.base not in self.subcommands: self.subcommands[x.base] = {} if x.subcommand_group: if x.subcommand_group not in self.subcommands[x.base]: self.subcommands[x.base][x.subcommand_group] = {} if x.name in self.subcommands[x.base][x.subcommand_group]: raise error.DuplicateCommand( f"{x.base} {x.subcommand_group} {x.name}" ) self.subcommands[x.base][x.subcommand_group][x.name] = x else: if x.name in self.subcommands[x.base]: raise error.DuplicateCommand(f"{x.base} {x.name}") self.subcommands[x.base][x.name] = x