From 54fdafb79254aa125d33540e4a63f51c43d42bc9 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 21 Mar 2017 00:11:12 -0400 Subject: [PATCH] [commands] Add BotBase.get_cog_commands to get all a cog's commands. Self-explanatory. This should help create help commands for a cog more easily. --- discord/ext/commands/bot.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 3f5292771..64dd80621 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -484,6 +484,31 @@ class BotBase(GroupMixin): """ return self.cogs.get(name) + def get_cog_commands(self, name): + """Gets a unique set of the cog's registered commands + without aliases. + + If the cog is not found, an empty set is returned. + + Parameters + ------------ + name: str + The name of the cog whose commands you are requesting. + + Returns + --------- + Set[:class:`Command`] + A unique set of commands without aliases that belong + to the cog. + """ + + try: + cog = self.cogs[name] + except KeyError: + return set() + + return {c for c in self.all_commands.values() if c.instance is cog} + def remove_cog(self, name): """Removes a cog from the bot.