public async Task ListSpecies(string taxonName) { // Get the taxon. Taxon taxon = await BotUtils.GetTaxonFromDb(taxonName); if (taxon is null) { await BotUtils.ReplyAsync_Error(Context, "No such taxon exists."); return; } // Get all species under that taxon. List <Species> species = new List <Species>(); species.AddRange(await BotUtils.GetSpeciesInTaxonFromDb(taxon)); species.Sort((lhs, rhs) => lhs.FullName.CompareTo(rhs.FullName)); // We might get a lot of species, which may not fit in one embed. // We'll need to use a paginated embed to reliably display the full list. // Create embed pages. List <EmbedBuilder> pages = EmbedUtils.SpeciesListToEmbedPages(species, fieldName: string.Format("Species in this {0} ({1}):", taxon.GetTypeName(), species.Count())); if (pages.Count <= 0) { pages.Add(new EmbedBuilder()); } // Add description to the first page. StringBuilder description_builder = new StringBuilder(); description_builder.AppendLine(taxon.GetDescriptionOrDefault()); if (species.Count() <= 0) { description_builder.AppendLine(); description_builder.AppendLine(string.Format("This {0} contains no species.", Taxon.GetRankName(taxon.type))); } // Add title to all pages. foreach (EmbedBuilder page in pages) { page.WithTitle(string.IsNullOrEmpty(taxon.CommonName) ? taxon.GetName() : string.Format("{0} ({1})", taxon.GetName(), taxon.GetCommonName())); page.WithDescription(description_builder.ToString()); page.WithThumbnailUrl(taxon.pics); } // Send the result. Bot.PaginatedMessage reply = new Bot.PaginatedMessage(); foreach (EmbedBuilder page in pages) { reply.Pages.Add(page.Build()); } await Bot.DiscordUtils.SendMessageAsync(Context, reply); }