Command class Null safety

A Command is a function bound to a name and arguments.

Commands can be text-only (meaning they can only be executed through sending a message with the bot's prefix) or slash-only (meaning they can only be executed through the means of a slash command). They can also be both, meaning they can be used both as a text and as a slash command.

Note that text-only commands can be Groups containing slash commands and vice versa, but slash commands cannot be groups containing other slash commands due to limitations on Discord.

Mixed in types

Constructors

Command(String name, String description, Function execute, {List<String> aliases = const [], CommandType type = CommandType.all, Iterable<GroupMixin> children = const [], Iterable<AbstractCheck> checks = const [], Iterable<AbstractCheck> singleChecks = const [], bool? hideOriginalResponse})
Create a new Command. [...]
Command.slashOnly(String name, String description, Function execute, {List<String> aliases = const [], Iterable<GroupMixin> children = const [], Iterable<AbstractCheck> checks = const [], Iterable<AbstractCheck> singleChecks = const [], bool? hideOriginalResponse})
Create a new slash-only Command. [...]
Command.textOnly(String name, String description, Function execute, {List<String> aliases = const [], Iterable<GroupMixin> children = const [], Iterable<AbstractCheck> checks = const [], Iterable<AbstractCheck> singleChecks = const [], bool? hideOriginalResponse})
Create a new text-only Command. [...]

Properties

aliases Iterable<String>
A Iterable of short names this command is aliased to.
final
checks Iterable<AbstractCheck>
A list of functions that must return true for any descendant of this group to be executed. These are called before command invocation and can cause it to fail. [...]
read-only, inherited
children Iterable<GroupMixin>
An iterable of all this groups children. [...]
read-only, inherited
childrenMap Map<String, GroupMixin>
A mapping of child names to children. [...]
final, inherited
depth int
The depth of this group. [...]
read-only, inherited
description String
A description of this command.
final
execute Function
The Function that is called when this command is invoked. [...]
final
fullName String
The full name of this group. [...]
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
hasSlashCommand bool
Whether this group contains any slash commands. [...]
read-only, inherited
hideOriginalResponse bool?
Whether to set the EPHEMERAL flag in the original response to interaction events. [...]
final
name String
The short name of this command, i.e without parent names.
final
onPostCall Stream<Context>
A Stream of Contexts that emits after Command.execute has successfully been called (no exceptions were thrown).
late, final, inherited
onPreCall Stream<Context>
A Stream of Contexts that emits after the checks have succeeded, but before Command.execute is called.
late, final, inherited
parent GroupMixin?
The parent of this group, if any.
read-only, inherited
postCallController StreamController<Context>
@protected, final, inherited
preCallController StreamController<Context>
@protected, final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
singleChecks List<AbstractCheck>
Similar to checks but only applies to this command.
final
type CommandType
The type of the command. [...]
final

Methods

addCommand(GroupMixin command) → void
Add a child to this group. [...]
override
check(AbstractCheck check) → void
Add a check to this groups checks.
inherited
getCommand(StringView view) Command?
Get a Command based off a StringView. [...]
inherited
getOptions(CommandsPlugin commands) Iterable<CommandOptionBuilder>
Build the options for registering this group to the Discord API for slash commands.
override
invoke(CommandsPlugin commands, Context context) Future<void>
Parse arguments contained in the context and call execute. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
registerChild(GroupMixin child) → void
Add a child to this group. [...]
@Deprecated('Use addCommand() instead'), inherited
singleCheck(AbstractCheck check) → void
Add a check to this commands singleChecks.
toString() String
A string representation of this object. [...]
override
walkCommands() Iterable<Command>
Iterate over all the commands in this group and any subgroups.
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited