ChatCommand constructor
- 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.
You might also be interested in:
- MessageCommand, for creating message commands;
- UserCommand, for creating user commands;
- CommandOptions.type, for changing how a command can be executed.
Implementation
ChatCommand(
this.name,
this.description,
this.execute, {
this.aliases = const [],
Iterable<ChatCommandComponent> children = const [],
Iterable<AbstractCheck> checks = const [],
Iterable<AbstractCheck> singleChecks = const [],
this.options = const CommandOptions(),
this.localizedNames,
this.localizedDescriptions,
}) {
if (!commandNameRegexp.hasMatch(name) || name != name.toLowerCase()) {
throw CommandRegistrationError('Invalid command name "$name"');
}
if ((localizedNames != null &&
localizedNames!.values
.any((names) => !commandNameRegexp.hasMatch(names) || names != names.toLowerCase()))) {
throw CommandRegistrationError('Invalid localized name for command "$name".');
}
RuntimeType<ChatContext> contextType = switch (resolvedOptions.type) {
CommandType.textOnly => const RuntimeType<MessageChatContext>.allowingDynamic(),
CommandType.slashOnly => const RuntimeType<InteractionChatContext>.allowingDynamic(),
null || CommandType.all => const RuntimeType<ChatContext>.allowingDynamic(),
};
_loadArguments(execute, contextType);
for (final child in children) {
addCommand(child);
}
for (final check in checks) {
super.check(check);
}
for (final singleCheck in singleChecks) {
this.singleCheck(singleCheck);
}
}