awaitModal method

  1. @override
Future<ModalContext> awaitModal(
  1. String customId,
  2. {Duration? timeout}
)
inherited

Wait for a user to submit a modal and return a context representing that submission.

customId is the id of the modal to wait for.

If timeout is set, this method will complete with an error after timeout has passed.

You might also be interested in:

Implementation

@override
Future<ModalContext> awaitModal(String customId, {Duration? timeout}) async {
  if (_delegate != null) {
    if (_delegate is! InteractionInteractiveContext) {
      throw UncaughtCommandsException(
        "Couldn't delegate awaitModal() to non-interaction context",
        _nearestCommandContext,
      );
    }

    return (_delegate as InteractionInteractiveContext).awaitModal(customId, timeout: timeout);
  }

  Future<ModalSubmitInteraction> event = client.onModalSubmitInteraction
      .map((e) => e.interaction)
      .where(
        (event) => event.data.customId == customId,
      )
      .first;

  if (timeout != null) {
    event = event.timeout(timeout);
  }

  ModalContext context = await commands.contextManager.createModalContext(await event);

  context._parent = this;
  _delegate = context;

  return context;
}