diff options
| author | Rapptz <[email protected]> | 2017-03-21 00:11:12 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-03-21 00:46:12 -0400 |
| commit | 54fdafb79254aa125d33540e4a63f51c43d42bc9 (patch) | |
| tree | 31915821a53a27fb859fa374f373371cc36eaa0d /discord/ext | |
| parent | [commands] Change GroupMixin.commands to all_commands (diff) | |
| download | discord.py-54fdafb79254aa125d33540e4a63f51c43d42bc9.tar.xz discord.py-54fdafb79254aa125d33540e4a63f51c43d42bc9.zip | |
[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.
Diffstat (limited to 'discord/ext')
| -rw-r--r-- | discord/ext/commands/bot.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 3f529277..64dd8062 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. |