Command
Attributes
The name of the command.
The coroutine that is executed when the command is called.
The long help text for the command.
The short help text for the command. If this is not specified then the first line of the long help text is used instead.
A replacement for arguments in the default help text.
The list of aliases the command can be invoked under.
A boolean that indicates if the command is currently enabled. If the command is invoked while it is disabled, then
DisabledCommand is raised to the event_command_error event. Defaults to True.The parent command that this command belongs to.
None if there isn’t one.The cog that this command belongs to.
None if there isn’t one.A list of predicates that verifies if the command could be executed with the given
Context as the sole parameter.The message prefixed into the default help command.
If
True, the default help command does not show this in the help output.If
False and a keyword-only argument is provided then the keyword only argument is stripped and handled as if it was a regular argument. If True then the keyword-only argument will pass in the rest of the arguments in a completely raw matter. Defaults to False.The subcommand that was invoked, if any.
If
True, ignores extraneous strings passed to a command if all its requirements are met. Otherwise event_command_error and local error handlers are called with TooManyArguments. Defaults to True.If
True, cooldown processing is done after argument parsing, which calls converters. If False then cooldown processing is done first and then the converters are called second. Defaults to False.Properties
Retrieves the parameter OrderedDict without the context or self parameters. Useful for inspecting signature.
Retrieves the fully qualified parent command name. This is the base command name required to execute it. For example, in
?one two three the parent name would be one two.Retrieves the parents of this command. If the command has no parents then it returns an empty list. For example in commands
?a b c test, the parents are [c, b, a].Retrieves the root parent of this command. If the command has no parents then it returns
None. For example in commands ?a b c test, the root parent is a.Retrieves the fully qualified command name. This is the full parent name with the command name as well. For example, in
?one two three the qualified name would be one two three.Returns a POSIX-like signature useful for help command output.
Gets the “short” documentation of a command. By default, this is the
brief attribute. If that lookup leads to an empty string then the first line of the help attribute is used instead.The name of the cog this command belongs to.
None otherwise.Methods
add_check
@check.
Parameters:
func: The function that will be used as a check.
remove_check
func: The function to remove from the checks.
update
Command instance with updated attribute. This works similarly to the @command decorator in terms of parameters in that they are passed to the Command or subclass constructors, sans the name and callback.
error
event_command_error event limited to a single command.
Raises: TypeError - The coroutine passed is not actually a coroutine.
before_invoke
TypeError - The coroutine passed is not actually a coroutine.
after_invoke
TypeError - The coroutine passed is not actually a coroutine.
is_on_cooldown
ctx(Context): The invocation context to use when checking the commands cooldown status.
bool - A boolean indicating if the command is on cooldown.
reset_cooldown
ctx(Context): The invocation context to reset the cooldown under.
can_run
checks attribute. This also checks whether the command is disabled.
Parameters:
ctx(Context): The ctx of the command currently being invoked.
bool - A boolean indicating if the command can be invoked.
Raises: CommandError - Any command error that was raised during a check call will be propagated by this function.
Group
Command and thus all options valid in Command are valid in here as well.
Attributes
Indicates if the group callback should begin parsing and invocation only if no subcommand was found. If this is
False, then the group callback will always be invoked first. Defaults to False.Indicates if the group’s commands should be case insensitive. Defaults to
None which means it inherits the parents or bots value.GroupMixin
Group and are allowed to register commands.
Attributes
A mapping of command name to
Command or subclass objects.The passed value telling if the commands should be case insensitive. Defaults to
None.Properties
The qualified case insensitive. This means that it will never return
None as it checks inherited values.A unique set of commands without aliases that are registered.
Methods
add_command
Command or its subclasses into the internal list of commands.
Parameters:
command(Command): The command to add.
ClientException: If the command is already registered.TypeError: If the command passed is not a subclass ofCommand.
remove_command
Command or subclasses from the internal list of commands. This could also be used as a way to remove aliases.
Parameters:
name(str): The name of the command to remove.
Optional[Command] - The command that was removed. If the name is not valid then None is returned instead.
walk_commands
get_command
Command or subclasses from the internal list of commands. This could also be used as a way to get aliases.
The name could be fully qualified (e.g. 'foo bar') will get the subcommand bar of the group command foo.
Parameters:
name(str): The name of the command to get.
Optional[Command] - The command that was requested. If not found, returns None.
command
@command and adds it to the internal command list via add_command().
group
@group and adds it to the internal command list via add_command().
Decorators
@command
Command or if called with @group, Group.
By default the help attribute is received automatically from the docstring of the function and is cleaned up with the use of inspect.cleandoc.
Parameters:
name(str): The name to create the command with. By default this uses the function name unchanged.cls: The class to construct with. By default this isCommand. You usually do not change this.**attrs: Keyword arguments to pass into the construction of the class denoted bycls.
TypeError: If the function is not a coroutine or is already a command.
@group
Group.
This is similar to the @command decorator but the cls parameter is set to Group by default.
Example:
@check
Command or its subclasses.
These checks should be predicates that take in a single parameter taking a Context. If the check returns a False-like value then during invocation a CheckFailure exception is raised and sent to the event_command_error event.
Parameters:
predicate(Callable[[Context], bool]): The predicate to check if the command should be invoked.
@check_any
@check that is added that checks if any of the checks passed will pass, i.e. using logical OR.
If all checks fail then CheckAnyFailure is raised to signal the failure.
Parameters:
*checks(Callable[[Context], bool]): An argument list of checks that have been decorated with the@checkdecorator.
TypeError: A check passed has not been decorated with the@checkdecorator.
@before_invoke
@after_invoke
@cooldown
Command or its subclasses.
A cooldown allows a command to only be used a specific amount of times in a specific time frame.
Parameters:
rate(int): The number of times a command can be used before triggering a cooldown.per(float): The amount of seconds to wait for a cooldown when it’s been triggered.type(BucketType): The type of cooldown to have.
@max_concurrency
Command or its subclasses.
This enables you to only allow a certain number of command invocations at the same time.
Parameters:
number(int): The maximum number of invocations of this command that can be running at the same time.per(BucketType): The bucket that this concurrency is based on.wait(bool): Whether the command should wait for the queue to be over.
@dm_only
@check that indicates this command must only be used in a DM context. Only private messages are allowed when using the command.
This check raises a special exception, PrivateMessageOnly that is inherited from CheckFailure.
@party_only
@check that indicates this command must only be used in a party context only. Basically, no private messages are allowed when using the command.
This check raises a special exception, PartyMessageOnly that is inherited from CheckFailure.
@is_owner
@check that checks if the person invoking this command is the owner of the bot.
This is powered by Bot.is_owner().
This check raises a special exception, NotOwner that is derived from CheckFailure.