Skip to content

Instantly share code, notes, and snippets.

@Gobot1234
Last active July 29, 2021 09:16
Show Gist options
  • Save Gobot1234/45cad24df63fc144e85a7f8c85812567 to your computer and use it in GitHub Desktop.
Save Gobot1234/45cad24df63fc144e85a7f8c85812567 to your computer and use it in GitHub Desktop.
A guide to sub-classing help with discord.py

Subclassing the help command in discord.py

This is going to be a short-ish guide on sub-classing help as ?tag new help isn't great at explaining things.

Choosing which help command to subclass

  1. Don't subclass HelpCommand unless you're going to override every one of the send_x methods, because that class does not do anything (it literally just returns None)
  2. DefaultHelpCommand is for the default help command (the code block one) Example of the default help command class
  3. MinimalHelpCommandis a minimalistic version of the help command, this is an example of the command produced if you copy ?tag new helpExample of the minimal help command class
  4. HelpCommand is a completely blank slate and can be subclassed to look any way you want, although most people use them for embeds My example of a help command Melody's help command

Getting started

The first thing you need with any subclassed help command is an __init__. For the main examples I will use the HelpCommand class as it is the one I am most familiar with.

class HelpCommand(commands.HelpCommand):
	def __init__(self):
		super().__init__(command_attrs={
	    		'help': 'Shows help about the bot, a command, or a category'  # This is the command.help string
	    		'cooldown': commands.Cooldown(1, 3.0, commands.BucketType.member),  # this is a custom attribute passed to the help command - cooldown
})

This example was taken from R. Danny but should work for any sub-classed help command.

Things you normally get in a cog/command

ctx - self.context

bot - self.context.bot

Methods to override

There are methods that you can override in your HelpCommand: The docs go much more in depth on these methods, I would advise reading these before creating one of the functions

async def send_bot_help(self, mapping) - handles the invocation of help with no args

async def send_cog_help(self, cog): - sends help for a specific cog

async def send_group_help(self, group) - sends help for an individual group

async def send_command_help(self, command) - sends help for an individual command

def get_command_signature(command) - a method for retrieving the signature (the args) of a command

Examples of above methods

These aren't to copy, or if you do please try to understand what they do.

def get_command...(command)

async def send_bot_help(self, mapping)

async def send_cog_help(self, cog):

Final message

If you are ever in any doubt or need help with writing a help command the discord.py server will always be willing to help.

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