Skip to content

Instantly share code, notes, and snippets.

Last active January 2, 2024 19:32
Show Gist options
  • Save nonchris/1c7060a14a9d94e7929aa2ef14c41bc2 to your computer and use it in GitHub Desktop.
Save nonchris/1c7060a14a9d94e7929aa2ef14c41bc2 to your computer and use it in GitHub Desktop.
A kinda advanced custom "help" command for your bots!
import discord
from discord.ext import commands
from discord.errors import Forbidden
"""This custom help command is a perfect replacement for the default one on any Discord Bot written in!
However, you must put "bot.remove_command('help')" in your bot, and the command must be in a cog for it to work.
Original concept by Jared Newsom (AKA Jared M.F.)
Rewritten and optimized by
You need to set three variables to make that cog run.
Have a look at line 51 to 57
async def send_embed(ctx, embed):
Function that handles the sending of embeds
-> Takes context and embed to send
- tries to send embed in channel
- tries to send normal message when that fails
- tries to send embed private with information abot missing permissions
If this all fails:
await ctx.send(embed=embed)
except Forbidden:
await ctx.send("Hey, seems like I can't send embeds. Please check my permissions :)")
except Forbidden:
f"Hey, seems like I can't send any message in {} on {}\n"
f"May you inform the server team about this issue? :slight_smile: ", embed=embed)
class Help(commands.Cog):
Sends this help message
def __init__(self, bot): = bot
# @commands.bot_has_permissions(add_reactions=True,embed_links=True)
async def help(self, ctx, *input):
"""Shows all modules of that bot"""
prefix = # ENTER YOUR PREFIX - loaded from config, as string or how ever you want!
version = # enter version of your code
# setting owner name - if you don't wanna be mentioned remove line 49-60 and adjust help text (line 88)
owner_name = # ENTER YOUR USERNAME#1234
# checks if cog parameter was given
# if not: sending all modules and commands not associated with a cog
if not input:
# checks if owner is on this server - used to 'tag' owner
owner = ctx.guild.get_member(owner).mention
except AttributeError as e:
owner = owner
# starting to build embed
emb = discord.Embed(title='Commands and modules',,
description=f'Use `{prefix}help <module>` to gain more information about that module '
# iterating trough cogs, gathering descriptions
cogs_desc = ''
for cog in
cogs_desc += f'`{cog}` {[cog].__doc__}\n'
# adding 'list' of cogs to embed
emb.add_field(name='Modules', value=cogs_desc, inline=False)
# integrating trough uncategorized commands
commands_desc = ''
for command in
# if cog not in a cog
# listing command if cog name is None and command isn't hidden
if not command.cog_name and not command.hidden:
commands_desc += f'{} - {}\n'
# adding those commands to embed
if commands_desc:
emb.add_field(name='Not belonging to a module', value=commands_desc, inline=False)
# setting information about author
emb.add_field(name="About", value=f"The Bots is developed by Chriѕ#0001, based on\n\
This version of it is maintained by {owner}\n\
Please visit to submit ideas or bugs.")
emb.set_footer(text=f"Bot is running {version}")
# block called when one cog-name is given
# trying to find matching cog and it's commands
elif len(input) == 1:
# iterating trough cogs
for cog in
# check if cog is the matching one
if cog.lower() == input[0].lower():
# making title - getting description from doc-string below class
emb = discord.Embed(title=f'{cog} - Commands',[cog].__doc__,
# getting commands from cog
for command in
# if cog is not hidden
if not command.hidden:
emb.add_field(name=f"`{prefix}{}`",, inline=False)
# found cog - breaking loop
# if input not found
# yes, for-loops have an else statement, it's called when no 'break' was issued
emb = discord.Embed(title="What's that?!",
description=f"I've never heard from a module called `{input[0]}` before :scream:",
# too many cogs requested - only one at a time allowed
elif len(input) > 1:
emb = discord.Embed(title="That's too much.",
description="Please request only one module at once :sweat_smile:",
emb = discord.Embed(title="It's a magical place.",
description="I don't know how you got here. But I didn't see this coming at all.\n"
"Would you please be so kind to report that issue to me on github?\n"
"Thank you! ~Chris",
# sending reply embed using our own function defined above
await send_embed(ctx, emb)
def setup(bot):

Hey, I just wanted to let you know that I've made a discord bot template on github, which offers some more utility funtions.
It's a solid base to begin with, also containing this help command :)

Have a look, if you're interested!

Copy link

rockwillck commented Jun 28, 2021

I added a join statement:

module = " ".join(module)

and then added:

if len(module) == 0:

but most importantly:
I got rid of

elif len(input) > 1:
emb = discord.Embed(title="That's too much.",
description="Please request only one module at once 😅",

because that was if the input was more than 1 character long, and that wasn't working.

And then I just added some more variables to make setup easier.

Copy link

Just subclass the HelpCommand lol

Copy link

The cmd is nice but it doesn't ignores the classes where no commands are in. For example the my profile save class. The cmd shows it up with typing the help cmd to discord but it's actually empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment