addConverter<T> method
- 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:
- Converter, for creating your own converters;
- registerDefaultConverters, for adding the default converters to a CommandsPlugin;
- getConverter, for retrieving the Converter for a specific type.
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;
}