respond method

  1. @override
Future<void> respond(
  1. Builder<Message> builder, {
  2. bool? updateMessage,
  3. bool? isEphemeral,
})
override

Send a response to this interaction.

Implementation

@override
Future<void> respond(Builder<Message> builder, {bool? updateMessage, bool? isEphemeral}) async {
  assert(updateMessage != true || isEphemeral != true, 'Cannot set isEphemeral to true if updateMessage is set to true');
  assert(updateMessage != true || builder is MessageUpdateBuilder, 'builder must be a MessageUpdateBuilder if updateMessage is true');
  assert(updateMessage == true || builder is MessageBuilder, 'builder must be a MessageBuilder if updateMessage is null or false');

  if (_didRespond) {
    throw AlreadyRespondedError(this);
  }

  if (!_didAcknowledge) {
    _didAcknowledge = true;
    _didRespond = true;
    _didUpdateMessage = updateMessage;
    _wasEphemeral = isEphemeral;

    if (updateMessage == true) {
      await manager.createResponse(id, token, InteractionResponseBuilder.updateMessage(builder as MessageUpdateBuilder));
    } else {
      await manager.createResponse(id, token, InteractionResponseBuilder.channelMessage(builder as MessageBuilder, isEphemeral: isEphemeral));
    }
  } else {
    assert(updateMessage == _didUpdateMessage || updateMessage == null, 'Cannot change the value of updateMessage between acknowledge and respond');
    assert(isEphemeral == _wasEphemeral || isEphemeral == null, 'Cannot change the value of isEphemeral between acknowledge and respond');

    _didRespond = true;

    if (_didUpdateMessage == true) {
      await manager.updateOriginalResponse(token, builder as MessageUpdateBuilder);
    } else {
      await manager.createFollowup(token, builder as MessageBuilder);
    }
  }
}