addConverter<T> method

void addConverter<T>(
  1. Converter<T> converter
)

Adds a converter to this CommandsPlugin.

Converters can be used to convert user input (Strings) to the type required by the command's callback function.

See the Converter docs for more info.

You might also be interested in:

Implementation

void addConverter<T>(Converter<T> converter) {
  RuntimeType<T> type = converter.output;

  // If we were given a type argument, use that as the target type.
  // We're guaranteed by type safety that [converter] will be a subtype
  // of Converter<T>, so we can assume that the provided type argument
  // is compatible with the converter.
  if (T != dynamic) {
    type = RuntimeType<T>();
  }

  _converters[type] = converter;
}