EmbedBuilder.fromGuildPreview constructor

EmbedBuilder.fromGuildPreview(
  1. GuildPreview preview
)

Create new instance of this to build an embed from a GuildPreview

Implementation

factory EmbedBuilder.fromGuildPreview(GuildPreview preview) {
  MineralClient client = ioc.use<MineralClient>();

  final EmbedBuilder embed = EmbedBuilder(
    title: preview.label,
    description: preview.description,
    thumbnail: preview.icon != null ? EmbedThumbnail(url: preview.icon!) : null,
    image: preview.discoverySplash != null ? EmbedImage(url: preview.discoverySplash!) : null,
    color: Color.invisible,
    timestamp: DateTime.now(),
    author: EmbedAuthor(name: client.user.username, iconUrl: client.user.decoration.defaultAvatarUrl)
  );

  embed.addField(name: 'Identifier', value: preview.id);
  embed.addField(name: 'Features', value: preview.features.map((feature) => '• $feature').join('\n'), inline: true);

  if (preview.stickers.isNotEmpty || preview.emojis.isNotEmpty) {
    List<Emoji> emojis = preview.emojis.values.toList();

    if(emojis.length > 25) {
      emojis = emojis.sublist(0, 25);
    }

    embed.addField(name: 'Emojis', value: emojis.map((emoji) => emoji).join(' ') + "...", inline: true);
  }

  embed.addField(name: '\u200B', value: '\u200B');
  embed.addField(name: 'Online members', value: '${preview.approximatePresenceCount} members', inline: true);
  embed.addField(name: 'Members', value: '${preview.approximateMemberCount} members', inline: true);
  embed.addField(name: '\u200B', value: '\u200B', inline: true);

  return embed;
}