diff --git a/redbot/cogs/downloader/downloader.py b/redbot/cogs/downloader/downloader.py index 1cc35383306..9c1cf31015d 100644 --- a/redbot/cogs/downloader/downloader.py +++ b/redbot/cogs/downloader/downloader.py @@ -1762,7 +1762,7 @@ def cog_name_from_instance(self, instance: object) -> str: return splitted[0] @commands.command() - async def findcog(self, ctx: commands.Context, command_name: str) -> None: + async def findcog(self, ctx: commands.Context, *, command_name: str) -> None: """Find which cog a command comes from. This will only work with loaded cogs. @@ -1774,14 +1774,45 @@ async def findcog(self, ctx: commands.Context, command_name: str) -> None: - `` The command to search for. """ + commands_found = [] command = ctx.bot.all_commands.get(command_name) - - if command is None: + if command is not None: + commands_found.append(command) + for app_command in ctx.bot.tree.get_commands(): + if app_command.name == command_name: + commands_found.append(app_command) + break + for app_command in ctx.bot.tree.get_commands(type=discord.AppCommandType.user): + if app_command.name == command_name: + commands_found.append(app_command) + break + for app_command in ctx.bot.tree.get_commands(type=discord.AppCommandType.message): + if app_command.name == command_name: + commands_found.append(app_command) + break + if not commands_found: + command_parts = command_name.split() + if len(command_parts) >= 2: + group_name = command_parts[0] + subcommand_name = command_parts[1] + for app_command in ctx.bot.tree.get_commands(): + if app_command.name == group_name and hasattr(app_command, "get_command"): + subcommand = app_command.get_command(subcommand_name) + if subcommand: + commands_found.append(subcommand) + break + + if not commands_found: await ctx.send(_("That command doesn't seem to exist.")) return + commands_found = commands_found[:4] + for command in commands_found: + cog = command.cog if hasattr(command, "cog") else getattr(command, "binding", None) + if not cog: + continue + # Check if in installed cogs - cog = command.cog if cog: cog_pkg_name = self.cog_name_from_instance(cog) installed, cog_installable = await self.is_installed(cog_pkg_name) @@ -1831,7 +1862,9 @@ async def findcog(self, ctx: commands.Context, command_name: str) -> None: embed.add_field(name=_("Repo URL:"), value=repo_url, inline=False) if installed and cog_installable.repo is not None and cog_installable.repo.branch: embed.add_field( - name=_("Repo branch:"), value=cog_installable.repo.branch, inline=False + name=_("Repo branch:"), + value=cog_installable.repo.branch, + inline=False, ) await ctx.send(embed=embed)