Hewp Commands¶
This section documents hewp commands, which aid in cweating dynyamicawwy genyewated hewp messages.
Cwasses¶
HewpCommand¶
- defadd_check
- asynccommand_cawwback
- defcommand_nyot_found
- asyncfiwtew_commands
- defget_bot_mapping
- d-defget_command_signyatuwe
- defget_destinyation
- defget_max_size
- asyncon_hewp_command_ewwow
- a-asyncpwepawe_hewp_command
- defwemuv_check
- defwemuv_mentions
- asyncsend_bot_hewp
- asyncsend_cog_hewp
- asyncsend_command_hewp
- asyncsend_ewwow_message
- asyncsend_gwoup_hewp
- defsubcommand_nyot_found
- 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]
Specifies if hidden commands shouwd be shown in the output. Defauwts to
False.- Type:
- verify_checks¶
Specifies i-i-if commands s-s-shouwd have theiw
Command.checkscawwed and vewified. IfTrue, awways cawwsCommand.checks. IfNone, onwy cawwsCommand.checksin a guiwd setting. IfFalse, nyevew cawwsCommand.checks. Defauwts toTrue.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
Commandconstwuctow.- Type:
- 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_withexcept pwopewwy h-h-handwes the case wheweContext.send_help()is used.If the hewp command was used weguwawwy then this wetuwns the
Context.invoked_withattwibute. Othewwise, if it the hewp command was c-cawwed usingContext.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]
- 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:
- 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.
- 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
commandpawametew.
'Command "{command.qualified_name}" has no subcommand named {string}'If the
commandpawametew has subcommands but nyot onye nyamedstring.
- P-Pawametews:
- Wetuwns:
The stwing to use when the command did nyot have the subcommand wequested.
- Wetuwn type:
- 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_checksandshow_hiddenattwibutes.- 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 tosorted()that takes aCommandas its sowe pawametew. Ifsortis passed asTruethen 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.
- get_destination()[source]¶
Wetuwns the
Messageablewhewe 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:
- 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.
- 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 cawwfilter_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 cawwfilter_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.
- 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¶
- defadd_command_fowmatting
- defadd_indented_commands
- defget_destinyation
- defget_ending_nyote
- asyncsend_pages
- defshowten_text
- 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.
- sort_commands¶
Whethew t-t-to sowt the commands in the o-output awphabeticawwy. Defauwts to
True.- Type:
- 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. IfFalse, nyonye o-of the hewp output is DM’d. IfNone, then the bot wiww onwy DM when the hewp message b-b-becomes too wong (dictated by mowe thandm_help_thresholdchawactews). Defauwts toFalse.- Type:
Optionyaw[
bool]
- dm_help_threshold¶
The n-nyumbew of chawactews the paginyatow must accumuwate befowe getting DM’d to the usew if
dm_helpis set toNone. Defauwts to 1000.- Type:
- 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:
- 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:
- get_ending_note()[source]¶
W-W-Wetuwns hewp command’s ending nyote. This is mainwy usefuw to uvwwide fow i18n puwposes.
- Wetuwn type:
- 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
indentspaces, padded tomax_sizefowwowed by the command’sCommand.short_docand then showtenyed to fit into thewidth.- 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, cawwsget_max_size()on the commands pawametew.
- await send_pages()[source]¶
A hewpew utiwity to send t-the page output fwom
paginatorto 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
Messageablewhewe 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:
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:
- 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:
- aliases_heading¶
The awias wist’s heading stwing used to wist the awiases o-of the command. Usefuw fow i18n. Defauwts to
"Aliases:".- Type:
- 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-IfFalse, nyonye of the hewp output is DM’d. IfNone, then the bot wiww onwy DM when t-the hewp message becomes too wong (dictated by mowe thandm_help_thresholdchawactews). Defauwts toFalse.- 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_helpis set toNone. D-D-Defauwts to 1000.- Type:
- 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:
- await send_pages()[source]¶
A hewpew utiwity to send the page output fwom
paginatorto 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:
- 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:
- 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.
- 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_nameoptionyawwy fowwowed by an En dash and the command’sCommand.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_headingbowded 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
Messageablewhewe 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: