build method

  1. @override
RawApiMap build()
override

Builds object to Map() instance;

Implementation

@override

/// Builds object to Map() instance;
RawApiMap build() {
  if (title != null && title!.length > 256) {
    throw EmbedBuilderArgumentException("Embed title is too long (256 characters limit)");
  }

  if (description != null && description!.length > 2048) {
    throw EmbedBuilderArgumentException("Embed description is too long (2048 characters limit)");
  }

  if (fields.length > 25) {
    throw EmbedBuilderArgumentException("Embed cannot contain more than 25 fields");
  }

  if (length > 6000) {
    throw EmbedBuilderArgumentException("Total length of embed cannot exceed 6000 characters");
  }

  return <String, dynamic>{
    if (title != null) "title": title,
    if (type != null) "type": type,
    if (description != null) "description": description,
    if (url != null) "url": url,
    if (timestamp != null) "timestamp": timestamp!.toUtc().toIso8601String(),
    if (color != null) "color": color!.value,
    if (footer != null) "footer": footer!.build(),
    if (imageUrl != null) "image": <String, dynamic>{"url": imageUrl},
    if (thumbnailUrl != null) "thumbnail": <String, dynamic>{"url": thumbnailUrl},
    if (author != null) "author": author!.build(),
    if (fields.isNotEmpty) "fields": fields.map((builder) => builder.build()).toList()
  };
}