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:
HelpCommandThe 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
HelpCommandclass. 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.
send_cog_help()command_not_found()subcommand_not_found()send_error_message()on_help_command_error()
- 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_checksandshow_hiddenattributes.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 tosorted()that takes a Union[Command,Command,Group] as its sole parameter. Ifsortis passed asTruethen this will default as the command name.
- Returns:
A list of commands that passed the filter.
- Return type:
- get_all_commands()
Retrieves bot the text command and app command bot mapping.
- get_bot_app_mapping()
Retrieves the app command bot mapping.
- get_cog(command, /)
Retrieves the proper cog that should be associated with the command.
- get_command_description(command, /, *, brief=False)
Helper method to resolve command description from a given command.
- Parameters:
- 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.
- get_destination()
Returns the
Messageablewhere 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.
- 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:
ctxandcommandparameters 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 theCogthat the command belongs to, orNoneif there isn’t one, and the value is a list of commands that belongs to that cog. App command will only be included whenHelpHybridCommand.include_appis 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.
- 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
commandsorcommandsfor group app commands. The commands returned not filtered. To do the filtering you will have to callfilter_commands()yourself.Changed in version 2.0:
groupparameter 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)
HelpPaginateProvider
- class starlight.HelpPaginateProvider(help_command)
Bases:
HelpMenuProviderView 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 theCogthat the command belongs to, orNoneif 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:
Components for HelpCommand
HelpPaginateBot
- class starlight.HelpPaginateBot(help_command, mapping, **options)
Bases:
SimplePaginationViewRepresents a cog-commands pagination for the PaginateHelpCommand that occurs when a general help command was requested.
This class should be inherited when changing the
PaginateHelpCommandsend_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
HelpHybridCommandclass 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:
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, orfloatvalues.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 thecommandparameter 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_strstrings only apply to the app command.