ChatCommand constructor

ChatCommand(
  1. String name,
  2. String description,
  3. Function execute,
  4. {Iterable<String> aliases = const [],
  5. Iterable<ChatCommandComponent> children = const [],
  6. Iterable<AbstractCheck> checks = const [],
  7. Iterable<AbstractCheck> singleChecks = const [],
  8. CommandOptions options = const CommandOptions(),
  9. Map<Locale, String>? localizedNames,
  10. Map<Locale, String>? localizedDescriptions}
)

Create a new ChatCommand.

You might also be interested in:

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);
  }
}