ChatCommand class
Represents a Discord Slash Command.
ChatCommands are commands with arguments. They can be invoked in two ways: through an interaction or through a text message sent by a user. In both cases, the arguments received from the Discord API are parsed using Converters to the type that your command expects.
For example, a simple command that responds with "Hi there!":
ChatCommand test = ChatCommand(
'test',
'A test command',
(IChatContext context) async {
context.respond(MessageBuilder.content('Hi there!'));
},
);
commands.addCommand(test);
You might also be interested in:
- CommandsPlugin.addCommand, for adding ChatCommands to your bot;
- ChatGroup, for creating command groups;
- MessageCommand, for creating Message Commands;
- UserCommand, for creating User Commands.
- Implemented types
Constructors
-
ChatCommand(String name, String description, Function execute, {Iterable<
String> aliases = const [], Iterable<ChatCommandComponent> children = const [], Iterable<AbstractCheck> checks = const [], Iterable<AbstractCheck> singleChecks = const [], CommandOptions options = const CommandOptions(), Map<Locale, String> ? localizedNames, Map<Locale, String> ? localizedDescriptions}) - Create a new ChatCommand.
Properties
-
aliases
→ Iterable<
String> -
The aliases for this entity.
final
-
argumentTypes
→ List<
RuntimeType> -
The types of the required and positional arguments of execute, in the order they appear.
final
-
checks
→ Iterable<
AbstractCheck> -
The checks that should be applied to this entity.
no setterinherited
-
children
→ Iterable<
ChatCommandComponent> -
A list of all the children of this group
no setterinherited
- description → String
-
The description of this entity.
final
- execute → Function
-
The function called to execute this command.
final
- fullName → String
-
The full name of this command.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasSlashCommand → bool
-
Whether this entity has a child entity that is a slash command or has a slash command itself.
no setterinherited
-
localizedDescriptions
→ Map<
Locale, String> ? -
The localized descriptions of this entity.
final
-
localizedNames
→ Map<
Locale, String> ? -
The localized names of this child.
Since you cannot add descriptions to UserCommand and MessageCommand, can't set localized descriptions too.
final
- name → String
-
The name of this child.
final
-
onPostCall
→ Stream<
ChatContext> -
A stream that emits contexts after the command callback is executed.
latefinalinherited
-
onPreCall
→ Stream<
ChatContext> -
A stream that emits contexts before the command callback is executed.
latefinalinherited
- options → CommandOptions
-
The options to use for this entity.
final
-
parent
↔ CommandGroup<
CommandContext> ? -
The parent of this child.
getter/setter pairinherited
- resolvedOptions → CommandOptions
-
Get the resolved options for this child.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
singleChecks
→ List<
AbstractCheck> -
A list of checks that apply only to this command.
final
Methods
-
addCommand(
covariant CommandRegisterable< ChatContext> command) → void -
Add a command to this group.
override
-
check(
AbstractCheck check) → void -
Add a check to this entity.
inherited
-
getCommand(
StringView view) → ChatCommand? -
Attempt to get a command from a string.
inherited
-
getOptions(
CommandsPlugin commands) → List< CommandOptionBuilder> -
Return the
CommandOptionBuilder
s that represent this entity for slash command registration.override -
invoke(
ChatContext context) → Future< void> -
Parse arguments, verify checks, call execute and handle call hooks.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
singleCheck(
AbstractCheck check) → void - Add a check to this command that does not apply to this commands children.
-
toString(
) → String -
A string representation of this object.
override
-
walkCommands(
) → Iterable< ChatCommand> -
Returns an iterable that recursively iterates over all the
Command
s in this group.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited