Converter<T> class
Contains metadata and parsing capabilities for a given type.
A Converter will convert textual user input received from the Discord API to the type requested by the current command. It also contains metadata about the type it converts.
nyxx_commands provides a set of converters for common argument types, a list of which can be found below. These converters are automatically added to CommandsPlugin instances and do not need to be added manually.
The list of default converters is as follows:
- stringConverter, which converts Strings;
- intConverter, which converts ints;
- doubleConverter, which converts doubles;
- boolConverter, which converts bools;
- snowflakeConverter, which converts Snowflakes;
- memberConverter, which converts Members;
- userConverter, which converts Users;
- guildChannelConverter, which converts GuildChannels;
- textGuildChannelConverter, which converts GuildTextChannels;
- voiceGuildChannelConverter, which converts GuildVoiceChannels;
- stageVoiceChannelConverter, which converts GuildStageChannels;
- roleConverter, which converts Roles;
- mentionableConverter, which converts CommandOptionMentionables;
- attachmentConverter, which converts Attachments.
You can override these default implementations with your own by calling CommandsPlugin.addConverter with your own converter for one of the types mentioned above.
You might also be interested in:
- CommandsPlugin.addConverter, for adding your own converters to your bot;
- FallbackConverter, for successively trying converters until one succeeds;
- CombineConverter, for piping the output of one converter into another;
- SimpleConverter, for creating simple converters.
Constructors
-
Converter(FutureOr<
T?> convert(StringView view, ContextData context), {Iterable<CommandOptionChoiceBuilder> ? choices, void processOptionCallback(CommandOptionBuilder)?, FutureOr<Iterable< autocompleteCallback(AutocompleteContext)?, CommandOptionType type = CommandOptionType.string, FutureOr<CommandOptionChoiceBuilder> ?>SelectMenuOptionBuilder> toSelectMenuOption(T)?, FutureOr<ButtonBuilder> toButton(T)?}) -
Create a new converter.
const
Properties
-
autocompleteCallback
→ (FutureOr<
Iterable< Function(AutocompleteContext)?)CommandOptionChoiceBuilder> ?> -
A function called to provide autocompletion
for arguments of this type.
final
-
choices
→ Iterable<
CommandOptionChoiceBuilder> ? -
The choices for this type.
final
-
convert
→ FutureOr<
T?> Function(StringView view, ContextData context) -
The function called to perform the conversion.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
output
→ RuntimeType<
T> -
The type that this converter parses.
no setter
- processOptionCallback → (void Function(CommandOptionBuilder)?)
-
A callback called with the CommandOptionBuilder created for an option using this converter.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
toButton
→ (FutureOr<
ButtonBuilder> Function(T)?) -
A function called to provide ButtonBuilders that can be used to represent an element
converted by this converter.
final
-
toSelectMenuOption
→ (FutureOr<
SelectMenuOptionBuilder> Function(T)?) -
A function called to provide SelectMenuOptionBuilders that can be used to represent an
element converted by this converter.
final
- type → CommandOptionType
-
The Discord Slash Command Argument Type
of the type that this converter parses.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited