Skip to content

Instantly share code, notes, and snippets.

@LennyPhoenix
Created January 20, 2021 12:10
Show Gist options
  • Save LennyPhoenix/979b5c80a15ecc2b69dc437cd483d911 to your computer and use it in GitHub Desktop.
Save LennyPhoenix/979b5c80a15ecc2b69dc437cd483d911 to your computer and use it in GitHub Desktop.
Help Command for Discord.py Cogs-Based Bot
@commands.command()
async def help(self, ctx, *, category=None):
"""This command!"""
if category is None:
embed = discord.Embed(
title="Category Listing and Uncatergorized Commands",
description="""Use `help *category*` to find out more about them!""",
colour=self.bot.main_colour
)
cogs_desc = ""
for cog in self.bot.cogs:
cogs_desc += f"`{cog}` - {self.bot.cogs[cog].__doc__}\n"
embed.add_field(
name="Categories",
value=cogs_desc,
inline=False
)
cmds = [
cmd for cmd in self.bot.walk_commands()
if not (cmd.cog_name or cmd.hidden)
]
if len(cmds) > 0:
cmds_desc = ""
for cmd in cmds:
sig = f"{cmd.name} {cmd.signature}".strip()
cmds_desc += f"`{sig}` - {cmd.help}\n"
embed.add_field(
name="Uncatergorized Commands",
value=cmds_desc,
inline=False
)
else:
bot_cogs = {
name.lower(): cog
for name, cog in self.bot.cogs.items()
}
if category.lower() in bot_cogs.keys():
embed = discord.Embed(
title=f"{list(self.bot.cogs.keys())[list(self.bot.cogs.values()).index(bot_cogs[category.lower()])]} Command Listing",
description=f"{bot_cogs[category.lower()].__doc__}",
colour=self.bot.main_colour
)
cmds = list(bot_cogs[category.lower()].walk_commands())
if len(cmds) > 0:
cmds_desc = ""
for cmd in cmds:
sig = f"{cmd.name} {cmd.signature}".strip()
cmds_desc += f"`{sig}` - {cmd.help}\n"
embed.add_field(
name="Commands",
value=cmds_desc,
inline=False
)
else:
embed.add_field(
name="No Commands",
value="Maybe they haven't been added yet?",
inline=False
)
else:
embed = discord.Embed(
title="Error!",
description=f"The category `{category}` doesn't even exist!",
colour=self.bot.main_colour
)
await ctx.send(embed=embed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment