Last active
January 12, 2022 06:09
-
-
Save DriftAsimov/cf993824343a9d369b38f6a08d2946df to your computer and use it in GitHub Desktop.
Discord.py hardcoded help command but it's better
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@bot.command() | |
async def help(ctx: commands.Context, *, name: str = None): | |
name = name.strip() | |
if not name: | |
commands = bot.commands | |
embed = discord.Embed(title="Commands Menu", color=0x8DDFE3) | |
embed.set_thumbnail(url=bot.user.avatar_url) | |
for name, cog in bot.cogs.items(): | |
embed.add_field( | |
name=cog.qualified_name, | |
value=", ".join([i.name for i in cog.get_commands()]), | |
inline=False, | |
) | |
misc = ", ".join([i.name for i in bot.commands if not i.cog]) | |
if len(misc) > 1: | |
embed.add_field(name="Miscellanous", value=misc) | |
await ctx.send(embed=embed) | |
else: | |
if name.lower() in [i.lower() for i in bot.cogs]: | |
raw_cog = [i for i in bot.cogs if name.lower() == i.lower()][0] | |
clog = bot.get_cog(raw_cog) | |
embed = discord.Embed(color=0x8DDFE3) | |
embed.title = clog.qualified_name | |
embed.description = clog.description | |
for command in clog.get_commands(): | |
embed.add_field(name=command.name, value=command.short_doc) | |
await ctx.send(embed=embed) | |
elif name.lower() in [i.name.lower() for i in bot.commands]: | |
await ctx.send("ay") | |
command = [i for i in bot.commands if name.lower() == i.name.lower()][0] | |
if not hasattr(command, "commands"): | |
embed = discord.Embed( | |
title=command.name, description=command.short_doc, color=0x8DDFE3 | |
) | |
embed.add_field( | |
name="Usage", | |
value=f"{ctx.prefix}{command.qualified_name} {command.signature}", | |
) | |
await ctx.send(embed=embed) | |
else: | |
embed = discord.Embed( | |
title=command.name, description=command.short_doc, color=0x8DDFE3 | |
) | |
for child in list(command.commands): | |
embed.add_field( | |
name=child.name, value=f"{command.name} {child.name}" | |
) | |
await ctx.send(embed=embed) |
Arigato! I am totally not late in replying
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a version of this command subclassed under
commands.HelpCommand
which is ironically a better version than the original one since this version shows the subcommands of the asked group
(for the ones who aren't the type of ppl to "doing things the way they are not intended to")
I didn't test this lmaoReferences:
Group
class