awaitSelection<T> method

  1. @override
Future<SelectMenuContext<T>> awaitSelection<T>(
  1. ComponentId componentId,
  2. {Converter<T>? converterOverride}
)
inherited

Wait for a user to select a single option from a multi-select menu and return a context representing that selection.

Will throw a StateError if more than one option is selected (for example, from a multi-select menu allowing more than one choice).

Implementation

@override
Future<SelectMenuContext<T>> awaitSelection<T>(
  ComponentId componentId, {
  Converter<T>? converterOverride,
}) async {
  if (delegate != null) {
    return delegate!.awaitSelection(
      componentId,
      converterOverride: converterOverride,
    );
  }

  SelectMenuContext<List<String>> rawContext =
      await commands.eventManager.nextSelectMenuEvent(componentId);

  SelectMenuContext<T> context = await commands.contextManager.createSelectMenuContext(
    rawContext.interaction,
    await parse(
      commands,
      _nearestCommandContext,
      StringView(rawContext.selected.single, isRestBlock: true),
      RuntimeType<T>(),
    ),
  );

  context._parent = this;
  _delegate = context;

  return context;
}