Help Command

This section covers all of the help command helpers and types of HelpCommand it has to offer.

Types of Help Command

HelpHybridCommand

class starlight.HelpHybridCommand(*args, **kwargs)

Bases: HelpCommand

The base class for help command with HybridCommand implementation. This should be the best way to make a help hybrid command.

Generally, this would include command, hybrid command, and app command compared to the HelpCommand class. There is helpful methods for easier integration between app command and text command.

If you have no control of the inheritance, you should use convert_help_hybrid() instead.

Parameters:
  • with_app_command (bool) – Whether to include app command implementation in your tree. Defaults to True. A shortcut to command_attrs=dict(with_app_command=True).

  • include_apps (bool) – Whether to include app commands. Only applicable if help command is invoked with app command. Defaults to True.

  • **options (Any) – Passed keyword arguments are sent to HelpCommand.

async command_callback(ctx, /, *, command=None)

This function is a coroutine.

The actual implementation of the help hybrid command.

It is not recommended to override this method and instead change the behaviour through the methods that actually get dispatched.

async filter_commands(commands, /, *, sort=False, key=None)

This function is a coroutine.

Returns a filtered list of commands and optionally sorts them.

This takes into account the verify_checks and show_hidden attributes.

This has support for app commands filtering for command hybrids.

Warning

verify_checks are not possible for app commands without slash invocation. The app command gets filtered when an app command have a check or interaction checks without slash invocation.

Parameters:
  • commands (Iterable[Union[Command, Command, Group]]) – An iterable of commands that are getting filtered.

  • sort (bool) – Whether to sort the result.

  • key (Optional[Callable[[Union[Command, Command, Group]], Any]]) – An optional key function to pass to sorted() that takes a Union[Command, Command, Group] as its sole parameter. If sort is passed as True then this will default as the command name.

Returns:

A list of commands that passed the filter.

Return type:

List[Union[Command, Command]

get_all_commands()

Retrieves bot the text command and app command bot mapping.

Returns:

A mapping of cog with text and app commands associated with it.

Return type:

Dict[Optional[Cog], List[Union[Command, Command, Group]]

get_bot_app_mapping()

Retrieves the app command bot mapping.

Returns:

A mapping of cog with app commands associated with it.

Return type:

Dict[Optional[Cog], List[Command]]

get_cog(command, /)

Retrieves the proper cog that should be associated with the command.

Parameters:

command (Union[Command, Command, Group]) – The command for cog retrieval

Returns:

Return associate cog instance. None if it has no associate cog.

Return type:

Optional[Cog]

get_command_description(command, /, *, brief=False)

Helper method to resolve command description from a given command.

Parameters:
  • command (Union[Command, Command, Group]) – Command to get the documentation from.

  • brief (bool) – Indicates whether to get the short documentation or long documentation for Command, Command, and Group. Defaults to False.

Returns:

An str that describes the command.

Return type:

Optional[str]

get_command_signature(command, /)

Implementation signature that is compatible with ~discord.app_commands.Command.

Parameters:

command (Union[Command, Command, Group]) – Command to get the signature from.

Returns:

The command signature in str form.

Return type:

str

get_destination()

Returns the Messageable where the help command will be output.

You can override this method to customise the behaviour.

By default this returns the context’s channel.

Returns:

The destination where the help command will be output.

Return type:

abc.Messageable

get_prefix(command, /)

Retrieves the proper prefix that should be associated with the command.

Parameters:

command (Union[Command, Group]) – The command for prefix retrieval.

Returns:

Return the proper prefix. App command should be strictly /.

Return type:

str

async prepare_help_command(ctx, command=None, /)

This function is a coroutine.

A low level method that can be used to prepare the help command before it does anything. For example, if you need to prepare some state in your subclass before the command does its processing then this would be the place to do it.

The default implementation does nothing.

Note

This is called inside the help command callback body. So all the usual rules that happen inside apply here as well.

Changed in version 2.0: ctx and command parameters are now positional-only.

Parameters:
  • ctx (Context) – The invocation context.

  • command (Optional[str]) – The argument passed to the help command.

async send_bot_help(mapping, /)

This function is a coroutine.

Handles the implementation of the bot command page in the help command. This function is called when the help command is called with no arguments.

It should be noted that this method does not return anything – rather the actual message sending should be done inside this method. Well behaved subclasses should use get_destination() to know where to send, as this is a customisation point for other users.

You can override this method to customise the behaviour.

Note

You can access the invocation context with HelpCommand.context.

Also, the commands in the mapping are not filtered. To do the filtering you will have to call filter_commands() yourself.

Parameters:

mapping (Mapping[Optional[Cog], List[Union[Command, Command, Group]]) – A mapping of cogs to commands that have been requested by the user for help. The key of the mapping is the Cog that the command belongs to, or None if there isn’t one, and the value is a list of commands that belongs to that cog. App command will only be included when HelpHybridCommand.include_app is set to True.

async send_command_help(command, /)

This function is a coroutine.

Handles the implementation of the single command page in the help command.

It should be noted that this method does not return anything – rather the actual message sending should be done inside this method. Well behaved subclasses should use get_destination() to know where to send, as this is a customisation point for other users.

You can override this method to customise the behaviour.

Note

You can access the invocation context with HelpCommand.context.

Showing Help

There are certain attributes and methods that are helpful for a help command to show such as the following:

These are helpful methods that were added for easier integration with app commands.

Parameters:

command (Union[Command, Command]) – The command that was requested for help.

async send_group_help(group, /)

This function is a coroutine.

Handles the implementation of the group page in the help command. This function is called when the help command is called with a group as the argument.

It should be noted that this method does not return anything – rather the actual message sending should be done inside this method. Well behaved subclasses should use get_destination() to know where to send, as this is a customisation point for other users.

You can override this method to customise the behaviour.

Note

You can access the invocation context with HelpCommand.context.

To get the commands that belong to this group without aliases see commands or commands for group app commands. The commands returned not filtered. To do the filtering you will have to call filter_commands() yourself.

Changed in version 2.0: group parameter is now positional-only.

Parameters:

group (Group) – The group that was requested for help.

PaginateHelpCommand

class starlight.PaginateHelpCommand(*args, **kwargs)

Bases: MenuHelpCommand

async format_bot_page(view, cmds)

Interface to display a general description of all bot commands.

When the total cog exceed PaginateHelpCommand.per_page, they are automatically paginated. This is shown as the first message of the help command.

Parameters:
  • view (HelpPaginateBot) – The view paginator that is used.

  • cmds (List[Command]) – The list of commands for each page.

Returns:

The value to be display on the Message.

Return type:

Union[discord.Embed, Dict[str, Any], str]

View Provider

To make view management in help command more manageable.

BaseHelpProvider

class starlight.BaseHelpProvider(help_command)

HelpMenuProvider

class starlight.HelpMenuProvider(help_command)

Bases: BaseHelpProvider

An implementation specifically for the MenuHelpCommand.

Its sole purpose is to provide a proper View instance depending on the command called. Users can subclass this class if they want to change the behaviour of the MenuHelpCommand. This should be supplied into the MenuHelpCommand for it to be applied properly.

Note that this class does not send any messages. That job belongs to MenuHelpCommand to provide its interface.

help_command

The help command instance that was binded to the provider.

Type:

MenuHelpCommand

async provide_bot_view(mapping)

This method is invoke when the MenuHelpCommand.send_bot_help is called. It provide a HelpMenuBot instance to be displayed on the help_command.

Overriding this method requires returning HelpMenuBot to supply a view for the MenuHelpCommand.send_bot_help method.

Parameters:

mapping (Dict[Optional[Cog], List[Command]]) – A filtered mapping of cogs to commands that have been requested by the user for help. The key of the mapping is the Cog that the command belongs to, or None if there isn’t one, and the value is a list of commands that belongs to that cog.

Returns:

The view for the MenuHelpCommand

Return type:

HelpMenuBot

async provide_cog_view(cog, cog_commands)

This method is invoke when the MenuHelpCommand.send_cog_help is called. It provide a HelpMenuCog instance to be displayed on the help_command.

Overriding this method requires returning HelpMenuCog to supply a view for the MenuHelpCommand.send_cog_help method.

Parameters:
  • cog (Cog) – The cog that was requested for help supplied from MenuHelpCommand.send_cog_help.

  • cog_commands (List[Command]) – Processed commands that belongs to the cog.

Returns:

The view for the MenuHelpCommand

Return type:

HelpMenuCog

async provide_command_view(command, /)

This method is invoke when the MenuHelpCommand.send_command_help is called. It provide a HelpMenuCommand instance to be displayed on the help_command. This is called when the user is requesting help on a command.

Overriding this method requires returning HelpMenuCommand to supply a view for the MenuHelpCommand.send_command_help method.

Parameters:

command (Command) – The requested command by the user.

Returns:

The view for the MenuHelpCommand

Return type:

HelpMenuCommand

async provide_error_view(error, /)

This method is invoke when the MenuHelpCommand.send_error_help is called. It provide a HelpMenuError instance to be displayed on the help_command. This is called when there is an error occurred invoking the help command.

Overriding this method requires returning HelpMenuCommand to supply a view for the MenuHelpCommand.send_error_help method.

Parameters:

error (str) – The error message that occurred.

Returns:

The view for the MenuHelpCommand

Return type:

HelpMenuError

async provide_group_view(group, /)

This method is invoke when the MenuHelpCommand.send_group_help is called. It provide a HelpMenuCommand instance to be displayed on the help_command. This is called when the user is requesting help on a group command.

Overriding this method requires returning HelpMenuCommand to supply a view for the MenuHelpCommand.send_command_help method.

Parameters:

group (Group) – The requested group by the user.

Returns:

The view for the MenuHelpCommand

Return type:

HelpMenuGroup

HelpPaginateProvider

class starlight.HelpPaginateProvider(help_command)

Bases: HelpMenuProvider

View provider for the PaginateHelpCommand.

async provide_bot_view(mapping)

This method is invoke when the HelpPaginateBot.send_bot_help is called.

Overriding this method requires returning HelpMenuBot to supply a view for the HelpPaginateBot.send_bot_help() method.

Parameters:

mapping (Dict[Optional[Cog], List[Command]]) – A filtered mapping of cogs to commands that have been requested by the user for help. The key of the mapping is the Cog that the command belongs to, or None if there isn’t one, and the value is a list of commands that belongs to that cog.

Returns:

The view for the PaginateHelpCommand

Return type:

HelpPaginateBot

Components for HelpCommand

HelpMenuBot

class starlight.HelpMenuBot(help_command, mapping, *, cog_per_page=None, **kwargs)

Bases: SimplePaginationView

Represents a cog pagination for the MenuHelpCommand that occurs when a general help command was requested.

This class should be inherited when changing the MenuHelpCommand send_bot_help view and override HelpMenuProvider.provide_bot_view.

Parameters:
  • help_command (MenuHelpCommand) – The help command that is associated with this view.

  • mapping (Dict[Optional[Cog], List[Command]]) – The full mapping of commands and Cog that will be display.

  • cog_per_page (Optional[int]) – The amount of cogs that are displayed in a given page. Defaults to MenuHelpCommand.per_page.

property current_dropdown

Current generated dropdown. Defaults to None before pagination starts.

async format_page(interaction, data)

Implementation for each page should be written in this method.

Parameters:
  • interaction (Optional[discord.Interaction]) – The interaction associated with the view. Can be None when context.interaction is None during the initial message send.

  • data (T) – The data that will be on each page. This type is based on data_source.

Returns:

The object that will displayed onto the Message. Returning a dictionary is a keyword arguments for the discord.Message.edit(). By default this returns the str of data argument.

Return type:

Union[Embed, Dict[str, Any], str]

format_view(interaction, data)

View manipulation should be made on this callback. This is called after format_page finishes invoking.

Parameters:
  • interaction (Optional[discord.Interaction]) – The interaction associated with the view. Can be None when context.interaction is None during the initial message send.

  • data (T) – The data that will be on each page. This type is based on data_source.

generate_dropdown(cogs, **kwargs)

Generates a Select that lists cogs.

User can use this to modify the dropdown.

Parameters:

cogs (List[Optional[Cog]]) –

Return type:

MenuDropDown

HelpMenuCog

class starlight.HelpMenuCog(cog, help_command, data_source, **kwargs)

Bases: SimplePaginationView

Represents a cog pagination for the MenuHelpCommand.

This class should be inherited when changing the MenuHelpCommand home button and provided with the cls_home_button key arguments.

Parameters:
  • cog (Optional[commands.Cog]) – The cog associated with the list of data sources.

  • help_command (MenuHelpCommand) – The help command that is associated with this view.

  • data_source (List[List[commands.Command]]) – The chunks of commands that will be display.

async format_page(interaction, data)

Implementation for each page should be written in this method.

Parameters:
  • interaction (Optional[discord.Interaction]) – The interaction associated with the view. Can be None when context.interaction is None during the initial message send.

  • data (T) – The data that will be on each page. This type is based on data_source.

Returns:

The object that will displayed onto the Message. Returning a dictionary is a keyword arguments for the discord.Message.edit(). By default this returns the str of data argument.

Return type:

Union[Embed, Dict[str, Any], str]

HelpMenuCommand

class starlight.HelpMenuCommand(help_command, command, **kwargs)

Bases: ViewAuthor

Implements a View on a command for the MenuHelpCommand.

This class should be inherited when changing the MenuHelpCommand command menu and override the HelpMenuProvider.provide_command_view.

Parameters:
  • help_command (MenuHelpCommand) – The help command that is associated with this view.

  • command (Command) – The command that will be display.

async start(context, *args, **kwargs)

Starts the view by sending a message

This should assign the message that was sent with the view.

Parameters:

context (Context) – The context that will be used to send a message.

HelpMenuGroup

class starlight.HelpMenuGroup(help_command, group, **kwargs)

Bases: ViewAuthor

Implements a View on a group for the MenuHelpCommand.

This class should be inherited when changing the MenuHelpCommand group menu and override the HelpMenuProvider.provide_group_view.

Parameters:
  • help_command (MenuHelpCommand) – The help command that is associated with this view.

  • group (Group) – The group that will be display.

async start(context, *args, **kwargs)

Starts the view by sending a message

This should assign the message that was sent with the view.

Parameters:

context (Context) – The context that will be used to send a message.

HelpMenuError

class starlight.HelpMenuError(help_command, error, **kwargs)

Bases: ViewAuthor

Implements a View on an error message for the MenuHelpCommand.

This class should be inherited when changing the MenuHelpCommand error menu and override the HelpMenuProvider.provide_error_view.

Parameters:
  • help_command (MenuHelpCommand) – The help command that is associated with this view.

  • error (str) – The error that will be display.

async on_click_delete(interaction, button)

Implements a stop button for the error message.

This essentially stop the view and defer the interaction.

Parameters:
async start(context, *args, **kwargs)

Starts the view by sending a message

This should assign the message that was sent with the view.

Parameters:

context (Context) – The context that will be used to send a message.

HelpPaginateBot

class starlight.HelpPaginateBot(help_command, mapping, **options)

Bases: SimplePaginationView

Represents a cog-commands pagination for the PaginateHelpCommand that occurs when a general help command was requested.

This class should be inherited when changing the PaginateHelpCommand send_bot_help view and override HelpPaginateProvider.provide_bot_view.

Parameters:
  • help_command (PaginateHelpCommand) – The help command that is associated with this view.

  • mapping (Dict[Optional[Cog], List[Command]]) – The mapping that was given by the help command.

async format_page(interaction, data)

Implementation for format_page that calls PaginateHelpCommand.format_bot_page(). This should be not overwritten by the user.

Returns:

The kwargs that will be given to the paginator.

Return type:

Optional[Union[discord.Embed, Dict[str, Any], str]]

Utility

Help command utility that may help in implementation.

convert_help_hybrid

starlight.convert_help_hybrid(help_command, **command_attrs)

Converts your help command into a hybrid help command.

This is still an experimental feature.

If you have control of the inheritance, you should use HelpHybridCommand class instead. This has a less feature compared to the class counterpart due to limitation.

Note

get_destination() is required to return a Context object for interaction compatibility since slash command does not allow sending message to other channel as the interaction response. As an alternative, send an initial response notifying the user on where the message went if you’ve decided to send messages at other channels.

Parameters:
  • help_command (HelpCommand) – Your help command that will be converted to hybrid.

  • **command_attrs (Any) – Attributes that will be assigned to the help command callback. You can set your related app command attribute here.

Returns:

A copy of your help command with hybrid compatibility.

Return type:

HelpCommand

help_autocomplete

starlight.help_autocomplete(*, parameter_name)

Associates the given parameter_name with the given autocomplete callback.

This is only used within a HybridHelpCommand class

Autocomplete is only supported on types that have str, int, or float values.

Example:

class MyHelpCommand(starlight.HybridHelpCommand):
    @starlight.help_autocomplete(parameter_name='command')
    async def help_command_autocomplete(self, interaction: discord.Interaction[commands.Bot], current: str
                                        ) -> List[app_commands.Choice[str]]:
        help_command = self.copy()
        help_command.context = await interaction.client.get_context(interaction)
        cogs_commands = await help_command.fuzzy_search_command_cog(interaction, current)
        return [
            app_commands.Choice(name=x.qualified_name, value=x.qualified_name)
            for x in cogs_commands
        ][:25]
Parameters:

parameter_name – The parameter_name to mark as autocomplete.

describe_help_command

starlight.describe_help_command(**descriptions)

Describes the parameters for the help command callback.

Each keyword argument should correspond to a parameter name and works similarly to discord.app_commands.describe(). This method can be useful to customise the command parameter description, for example:

@starlight.describe_help_command(command="command or category")
class MyHelpCommand(starlight.MenuHelpCommand):
    pass
Parameters:

**parameters (Union[str, locale_str]) – The parameter descriptions. locale_str strings only apply to the app command.