parse

open suspend fun <T : Arguments> parse(builder: () -> T, context: ChatCommandContext<*>): T

Given a builder returning an Arguments subclass and CommandContext, parse the command's arguments into the Arguments subclass and return it.

This is a fairly complex function. It works like this:

  1. Enumerate all of the converters provided by the Arguments subclass, mapping them to their display names for easier keyword argument parsing.

  2. Parse out the keyword arguments and store them in a map, leaving only the positional arguments in the list.

  3. Loop over the converters, handing them the values they require.

    • If a converter has keyword arguments, use those instead of taking a value from the list of arguments.

    • For single, defaulting or optional converters, pass them a single argument and continue to the next.

    • For coalescing or multi converters:

      • If it's a keyword argument, pass it all of the keyed values and continue.

      • If it's positional, pass it all remaining positional arguments and remove those that were converted.

Return

Built Arguments object, with converters filled.

Parameters

builder

Builder returning an Arguments subclass - usually the constructor.

context

MessageCommand context for this command invocation.

Throws

Thrown based on a lot of possible cases. This is intended for display on Discord.