createFollowup method

Future<Message> createFollowup(
  1. String token,
  2. MessageBuilder builder,
  3. {bool? isEphemeral}
)

Create a followup to an interaction.

Implementation

Future<Message> createFollowup(String token, MessageBuilder builder, {bool? isEphemeral}) async {
  final route = HttpRoute()
    ..webhooks(id: applicationId.toString())
    ..add(HttpRoutePart(token));

  final builtMessagePayload = builder.build();
  if (isEphemeral != null) {
    builtMessagePayload['flags'] = (builtMessagePayload['flags'] as int? ?? 0) | (isEphemeral ? MessageFlags.ephemeral.value : 0);
  }

  final HttpRequest request;
  if (!identical(builder.attachments, sentinelList) && builder.attachments?.isNotEmpty == true) {
    final attachments = builder.attachments!;

    final files = <MultipartFile>[];
    for (int i = 0; i < attachments.length; i++) {
      files.add(MultipartFile.fromBytes(
        'files[$i]',
        attachments[i].data,
        filename: attachments[i].fileName,
      ));

      ((builtMessagePayload['attachments'] as List)[i] as Map)['id'] = i.toString();
    }

    request = MultipartRequest(
      route,
      method: 'POST',
      jsonPayload: jsonEncode(builtMessagePayload),
      files: files,
      applyGlobalRateLimit: false,
    );
  } else {
    request = BasicRequest(
      route,
      method: 'POST',
      body: jsonEncode(builtMessagePayload),
      applyGlobalRateLimit: false,
    );
  }

  final response = await client.httpHandler.executeSafe(request);

  final channelId = Snowflake.parse((response.jsonBody as Map<String, Object?>)['channel_id']!);
  final message = (client.channels[channelId] as PartialTextChannel).messages.parse(response.jsonBody as Map<String, Object?>);

  client.updateCacheWith(message);
  return message;
}