Hewp Commands

This section documents hewp commands, which aid in cweating dynyamicawwy genyewated hewp messages.

Cwasses

HewpCommand

class disnake.ext.commands.HelpCommand(*args, **kwargs)[source]

The base impwementation fow hewp command fowmatting.

Nyote

Intewnyawwy instances of this cwass awe deep copied evewy time the command i-i-itsewf is invoked to pwevent a wace condition mentionyed in #2123.

This means that wewying on the state of this cwass to be the same between command invocations wouwd nyot w-w-wowk as expected.

context

The context that invoked this hewp fowmattew. This is genyewawwy set aftew the hewp command assignyed, command_callback(), has been cawwed.

Type:

Optionyaw[Context]

show_hidden

Specifies if hidden commands shouwd be shown in the output. Defauwts to False.

Type:

bool

verify_checks

Specifies i-i-if commands s-s-shouwd have theiw Command.checks cawwed and vewified. If True, awways cawws Command.checks. If None, onwy cawws Command.checks in a guiwd setting. If False, nyevew cawws Command.checks. Defauwts to True.

Changed in vewsion 1.7.

Type:

Optionyaw[bool]

command_attrs

A dictionyawy of options to pass i-in fow the constwuction of the hewp command. This awwows you to change t-t-the command behaviouw without actuawwy changing the impwementation of the command. The attwibutes w-w-wiww be the same as the onyes passed in the Command constwuctow.

Type:

dict

add_check(func)[source]

Adds a check to the hewp command.

Nyew in vewsion 1.4.

Pawametews:

func – The function that wiww b-be used as a check.

remove_check(func)[source]

Wemuvs a check fwom the hewp command.

This function is idempotent a-and w-w-wiww nyot waise an exception if the f-f-function is nyot in the command’s checks.

Nyew in vewsion 1.4.

Pawametews:

func – The function to wemuv fwom the checks.

get_bot_mapping()[source]

Wetwieves the bot mapping passed to send_bot_help().

property invoked_with[source]

Simiwaw to Context.invoked_with except pwopewwy h-h-handwes the case whewe Context.send_help() is used.

If the hewp command was used weguwawwy then this wetuwns the Context.invoked_with attwibute. Othewwise, if it the hewp command was c-cawwed using Context.send_help() then it wetuwns the intewnyaw command nyame of the hewp command.

Wetuwns:

The command nyame that twiggewed this invocation.

Wetuwn type:

Optionyaw[str]

get_command_signature(command)[source]

Wetwieves the signyatuwe powtion of the hewp page.

Pawametews:

command (Command) – The command to get the signyatuwe of.

W-Wetuwns:

The signyatuwe fow the command.

Wetuwn type:

str

remove_mentions(string)[source]

Wemuvs mentions fwom the stwing to pwevent abuse.

This incwudes @everyone, @here, membew mentions and wowe mentions.

Wetuwns:

The stwing with mentions wemuvd.

Wetuwn type:

str

property cog[source]

A pwopewty fow wetwieving ow setting the cog fow the hewp command.

W-W-When a cog is set fow the hewp command, i-it is as-if the hewp command bewongs to that cog. Aww c-c-cog speciaw methods w-w-wiww appwy to the hewp command a-a-and it wiww be automaticawwy unset on unwoad.

To unbind the cog fwom the hewp command, you can set it to None.

Wetuwns:

The cog that is cuwwentwy set fow the hewp command.

Wetuwn type:

Optionyaw[Cog]

command_not_found(string)[source]

This function c-c-couwd be a c-c-cowoutinye.

A m-m-method cawwed when a command is n-n-nyot found in the h-hewp command. This is usefuw to uvwwide fow i18n.

D-Defauwts to No command called {0} found.

Pawametews:

stwing (str) – The stwing that contains the invawid command. Nyote that this h-h-has had mentions wemuvd to p-p-pwevent abuse.

Wetuwns:

The stwing to use when a c-command has nyot been found.

Wetuwn type:

str

subcommand_not_found(command, string)[source]

This function couwd b-b-be a cowoutinye.

A method cawwed when a c-command did nyot have a s-s-subcommand wequested in the h-hewp command. This is usefuw to uvwwide fow i18n.

Defauwts to eithew:

  • 'Command "{command.qualified_name}" has no subcommands.'
    • If thewe is nyo subcommand in the command pawametew.

  • 'Command "{command.qualified_name}" has no subcommand named {string}'
    • If the command pawametew has subcommands but nyot onye nyamed string.

P-Pawametews:
  • command (Command) – The command that did nyot have the subcommand wequested.

  • stwing (str) – The stwing that contains the invawid subcommand. Nyote t-t-that this has had mentions wemuvd to pwevent abuse.

Wetuwns:

The stwing to use when the command did nyot have the subcommand wequested.

Wetuwn type:

str

await filter_commands(commands, *, sort=False, key=None)[source]

This function is a cowoutinye.

Wetuwns a fiwtewed wist of commands and optionyawwy sowts them.

This takes into account t-the verify_checks and show_hidden attwibutes.

Pawametews:
  • commands (Itewabwe[Command]) – An itewabwe of commands that awe getting f-f-fiwtewed.

  • sowt (bool) – Whethew t-to sowt the wesuwt.

  • key (Optionyaw[Cawwabwe[[Command], Any]]) – An optionyaw key function to pass to sorted() that takes a Command as its sowe pawametew. If sort is passed as True then this wiww defauwt to using the command nyame.

Wetuwns:

A-A-A wist of commands that passed the fiwtew.

Wetuwn type:

Wist[Command]

get_max_size(commands)[source]

Wetuwns the w-wawgest nyame wength o-o-of the specified command wist.

Pawametews:

commands (Sequence[Command]) – A sequence of c-c-commands to c-check fow the wawgest size.

Wetuwns:

The maximum width of the commands.

Wetuwn type:

int

get_destination()[source]

Wetuwns the Messageable whewe the hewp command wiww be output.

You can uvwwide this method t-to customise the behaviouw.

By defauwt this wetuwns the context’s channyew.

Wetuwns:

The d-d-destinyation whewe the h-h-hewp c-c-command wiww be output.

Wetuwn type:

abc.Messageable

await send_error_message(error)[source]

This function is a cowoutinye.

Handwes the impwementation when an ewwow happens in the hewp command. Fow exampwe, the wesuwt of command_not_found() wiww be passed hewe.

You can uvwwide this method to customise the behaviouw.

By defauwt, this s-s-sends the ewwow message to the destinyation specified by get_destination().

Nyote

You can access the invocation context with HelpCommand.context.

Pawametews:

ewwow (str) – The ewwow message to dispway to t-t-the usew. Nyote that this has had mentions wemuvd to pwevent abuse.

await on_help_command_error(ctx, error)[source]

This function is a cowoutinye.

The hewp command’s ewwow handwew, as specified by Ewwow Handwing.

Usefuw to uvwwide if you nyeed some specific behaviouw when the ewwow handwew is cawwed.

By defauwt this method does nyothing and just pwopagates to the defauwt ewwow handwews.

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

  • ewwow (CommandError) – The ewwow that was waised.

await send_bot_help(mapping)[source]

This function is a cowoutinye.

Handwes the i-impwementation of the bot command p-page in the hewp command. This function is cawwed when the hewp c-command is c-cawwed with nyo awguments.

It shouwd be nyoted that this method does nyot wetuwn anything – wathew t-the actuaw message sending shouwd be donye inside this method. Weww behaved s-subcwasses shouwd use get_destination() to knyow whewe to send, as this is a c-c-customisation point fow othew usews.

You can uvwwide this method to customise the behaviouw.

Nyote

You can access the invocation context with HelpCommand.context.

Awso, the commands in the mapping awe nyot fiwtewed. To do the fiwtewing you wiww have to caww filter_commands() youwsewf.

Pawametews:

mapping (M-M-Mapping[Optionyaw[Cog], Wist[Command]]) – A mapping of cogs to commands that have been w-wequested by the usew fow hewp. The key of the mapping is the Cog that the command bewongs to, ow None if thewe isn’t onye, and the vawue is a wist of commands that bewongs to that cog.

await send_cog_help(cog)[source]

This function is a cowoutinye.

Handwes the impwementation of the c-c-cog p-page in the hewp command. This function is c-cawwed when the hewp command is c-cawwed with a cog as the awgument.

It shouwd be nyoted that this method does nyot wetuwn anything – wathew the actuaw message s-sending shouwd be donye inside this method. Weww b-b-behaved subcwasses shouwd use get_destination() to knyow whewe to send, as this is a customisation point fow othew usews.

You can uvwwide this method t-t-to customise the behaviouw.

Nyote

You can access the invocation context with HelpCommand.context.

To get the commands that bewong to this cog see Cog.get_commands(). The commands wetuwnyed nyot fiwtewed. To do the fiwtewing you wiww have to caww filter_commands() youwsewf.

Pawametews:

cog (Cog) – The cog that was wequested fow hewp.

await send_group_help(group)[source]

This function is a cowoutinye.

Handwes the impwementation of the gwoup page in t-t-the hewp command. This function is cawwed when the h-h-hewp command is cawwed with a gwoup as the awgument.

It shouwd be nyoted that this method does nyot wetuwn anything – wathew the actuaw message sending shouwd be donye inside this method. Weww behaved subcwasses shouwd use get_destination() to knyow whewe to send, as this is a customisation point fow othew usews.

Y-You can uvwwide this method to c-customise the behaviouw.

Nyote

You can access the invocation context with HelpCommand.context.

To get the commands t-that bewong to this gwoup without awiases see Group.commands. The commands wetuwnyed awe nyot fiwtewed. To do the fiwtewing you wiww have to caww filter_commands() youwsewf.

Pawametews:

gwoup (Group) – The gwoup that was wequested fow hewp.

await send_command_help(command)[source]

This function is a cowoutinye.

Handwes the impwementation of the singwe command page i-in the hewp command.

I-I-It shouwd be nyoted that t-t-this method does nyot wetuwn anything – wathew the actuaw message sending shouwd be d-d-donye inside this method. Weww behaved subcwasses shouwd use get_destination() to knyow whewe t-to send, as this is a customisation point fow othew u-usews.

Y-Y-You can uvwwide this m-method to customise the behaviouw.

Nyote

You can a-a-access the invocation context with HelpCommand.context.

Showing Hewp

Thewe awe c-cewtain attwibutes and methods that a-a-awe h-h-hewpfuw fow a hewp c-command to show s-such as the fowwowing:

Thewe awe mowe t-than just these attwibutes but feew fwee to pway awound with these to hewp y-y-you get stawted to get the output that you want.

Pawametews:

command (Command) – The command that was wequested fow hewp.

await prepare_help_command(ctx, command=None)[source]

This function is a cowoutinye.

A wow wevew method that can be used to pwepawe the hewp command befowe it does anything. Fow exampwe, if you nyeed to pwepawe some state i-i-in youw subcwass befowe the command does its pwocessing then this w-w-wouwd be the pwace to do it.

The defauwt impwementation does nyothing.

Nyote

This is cawwed inside the hewp command c-cawwback body. So aww the usuaw wuwes that happen inside appwy hewe as weww.

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

  • command (Optionyaw[str]) – The awgument passed to the hewp command.

await command_callback(ctx, *, command=None)[source]

This function is a cowoutinye.

The actuaw impwementation of the hewp command.

It is nyot wecommended to uvwwide this method a-and instead change the behaviouw thwough the methods that actuawwy get d-d-dispatched.

DefauwtHewpCommand

class disnake.ext.commands.DefaultHelpCommand(*args, **kwargs)[source]

The impwementation of the defauwt hewp command.

This inhewits fwom HelpCommand.

It extends it with the fowwowing attwibutes.

width

The maximum nyumbew of c-chawactews that fit in a winye. Defauwts to 80.

Type:

int

sort_commands

Whethew t-t-to sowt the commands in the o-output awphabeticawwy. Defauwts to True.

Type:

bool

dm_help

A twiboow that indicates if the hewp command shouwd DM the usew instead of sending it to the channyew it weceived it fwom. If the boowean is set to True, then aww hewp output is DM’d. If False, nyonye o-of the hewp output is DM’d. If None, then the bot wiww onwy DM when the hewp message b-b-becomes too wong (dictated by mowe than dm_help_threshold chawactews). Defauwts to False.

Type:

Optionyaw[bool]

dm_help_threshold

The n-nyumbew of chawactews the paginyatow must accumuwate befowe getting DM’d to the usew if dm_help is set to None. Defauwts to 1000.

Type:

int

indent

How much to indent the commands fwom a heading. Defauwts to 2.

Type:

int

commands_heading

The command wist’s heading s-stwing used when the hewp command is invoked with a categowy nyame. Usefuw fow i18n. Defauwts to "Commands:"

Type:

str

no_category

The stwing used when thewe is a command which does nyot bewong to any categowy(cog). Usefuw fow i18n. Defauwts to "No Category"

Type:

str

paginator

The paginyatow used to paginyate the hewp command output.

T-Type:

Paginator

shorten_text(text)[source]

Showtens text to fit into the width.

Wetuwn type:

str

get_ending_note()[source]

W-W-Wetuwns hewp command’s ending nyote. This is mainwy usefuw to uvwwide fow i18n puwposes.

Wetuwn type:

str

add_indented_commands(commands, *, heading, max_size=None)[source]

Indents a wist of commands aftew the specified heading.

The fowmatting is added t-t-to the paginator.

The defauwt impwementation is the command nyame indented by indent spaces, padded to max_size fowwowed by the command’s Command.short_doc and then showtenyed to fit into the width.

Pawametews:
  • commands (Sequence[Command]) – A wist of commands to indent fow output.

  • heading (str) – The heading to add to the output. This is onwy added if the wist of commands is gweatew than 0.

  • max_size (Optionyaw[int]) – T-T-The max size to use fow the gap between indents. If unspecified, cawws get_max_size() on the commands pawametew.

await send_pages()[source]

A hewpew utiwity to send t-the page output fwom paginator to the destinyation.

add_command_formatting(command)[source]

A utiwity function to fowmat the nyon-indented bwock of commands and gwoups.

Pawametews:

command (Command) – The command to f-fowmat.

get_destination()[source]

Wetuwns the Messageable whewe the hewp command wiww be output.

You can uvwwide this method to customise the behaviouw.

By d-defauwt this wetuwns the context’s channyew.

Wetuwns:

The destinyation whewe the hewp c-command wiww be output.

Wetuwn type:

abc.Messageable

MinyimawHewpCommand

class disnake.ext.commands.MinimalHelpCommand(*args, **kwargs)[source]

An impwementation of a hewp command with minyimaw output.

This inhewits fwom HelpCommand.

sort_commands

Whethew to sowt the commands in the output awphabeticawwy. Defauwts to True.

Type:

bool

commands_heading

The command wist’s heading s-s-stwing used w-w-when the hewp command is invoked with a categowy nyame. Usefuw fow i18n. Defauwts to "Commands"

Type:

str

aliases_heading

The awias wist’s heading stwing used to wist the awiases o-of the command. Usefuw fow i18n. Defauwts to "Aliases:".

Type:

str

dm_help

A twiboow that indicates if the hewp command shouwd DM the usew instead of sending it to the channyew it weceived it f-fwom. If the boowean is set to True, then aww hewp output i-i-is DM’d. I-If False, nyonye of the hewp output is DM’d. If None, then the bot wiww onwy DM when t-the hewp message becomes too wong (dictated by mowe than dm_help_threshold chawactews). Defauwts to False.

Type:

Optionyaw[bool]

dm_help_threshold

The nyumbew of c-c-chawactews the paginyatow must accumuwate befowe getting DM’d to the usew if dm_help is set to None. D-D-Defauwts to 1000.

Type:

int

no_category

The stwing used when thewe is a command which d-d-does nyot bewong to any categowy(cog). Usefuw fow i18n. Defauwts to "No Category"

Type:

str

paginator

The paginyatow used to paginyate the hewp command output.

Type:

Paginator

await send_pages()[source]

A hewpew utiwity to send the page output fwom paginator to the destinyation.

get_opening_note()[source]

Wetuwns hewp command’s openying nyote. This is mainwy usefuw to uvwwide fow i18n puwposes.

The defauwt impwementation wetuwns

Use `{prefix}{command_name} [command]` for more info on a command.
You can also use `{prefix}{command_name} [category]` for more info on a category.
Wetuwns:

The hewp command openying nyote.

Wetuwn type:

str

get_command_signature(command)[source]

Wetwieves the signyatuwe powtion of the hewp page.

Pawametews:

command (Command) – The command to get the signyatuwe of.

Wetuwns:

The signyatuwe fow the command.

Wetuwn type:

str

get_ending_note()[source]

Wetuwn the hewp command’s ending nyote. This is mainwy usefuw to uvwwide fow i18n p-p-puwposes.

T-The defauwt impwementation does nyothing.

Wetuwns:

The hewp command ending n-n-nyote.

Wetuwn type:

str

add_bot_commands_formatting(commands, heading)[source]

Adds the minyified bot heading with commands to the output.

The f-fowmatting shouwd be added to the paginator.

The defauwt impwementation is a bowd undewwinye heading fowwowed by commands sepawated by an EN SPACE (U+2002) in the nyext winye.

Pawametews:
  • commands (Sequence[Command]) – A wist of commands that bewong to the heading.

  • heading (str) – The heading to add to the winye.

add_subcommand_formatting(command)[source]

A-A-Adds fowmatting infowmation on a subcommand.

The fowmatting shouwd be added to the paginator.

The defauwt impwementation is the pwefix and the Command.qualified_name optionyawwy fowwowed by an En dash and the command’s Command.short_doc.

Pawametews:

command (Command) – The command to show infowmation o-o-of.

add_aliases_formatting(aliases)[source]

Adds the fowmatting infowmation on a command’s awiases.

The fowmatting shouwd be added to the paginator.

The defauwt impwementation is the aliases_heading bowded fowwowed by a comma sepawated wist of awiases.

This is nyot cawwed if thewe awe nyo awiases to fowmat.

Pawametews:

awiases (Sequence[str]) – A wist of awiases to fowmat.

add_command_formatting(command)[source]

A utiwity function to fowmat commands and gwoups.

Pawametews:

command (Command) – The command to f-fowmat.

get_destination()[source]

Wetuwns the Messageable whewe the hewp command wiww be output.

You can uvwwide this method to c-c-customise the behaviouw.

By defauwt this wetuwns the context’s channyew.

Wetuwns:

The destinyation whewe the hewp command wiww be output.

Wetuwn t-t-type:

abc.Messageable