How to use Embeds
Embeds are generally used to display the preview of certain content or a link, but they can be used as content itself.
Content and Custom embeds
There are 2 kinds of embeds, content embeds and custom embeds(may also be called rich embeds).
Content embeds are used to automatically generate a preview of a link. If you add a hyperlink, the Guilded client will pull OpenGraph metadata from the linked website and display the contents according to the fetch data. Content embeds may differ in design, unlike custom embeds(website embeds vs share feature vs server invite).
Custom embeds are similar to content website embeds in terms of how they look, but they are fully customizable, meaning, you can set custom colour of the side border, add fields you want, etc. Custom embeds do not require a hyperlink to be added and it can be added freely to a message. They are generally used for webhooks to display events/new content or for bots to have a fancy output that is more understandable from a glance. Content embeds cannot look like shared messages or team invites as of now.
Creating a custom embed
Basics
To create an embed, you need to create a new instance of Embed. From that point, you can use embed constructor parameters, object initializers or methods to generate content for the embed. As an example:
using Guilded.Base.Embeds;
Embed embed = new Embed { Title = "This is the title of the embed", Description = "Description", Footer = new EmbedFooter("The footer text of the embed") };
And now we can send the embed we made:
await msgCreated.ReplyAsync(embed);
This produces:
Due to design choices, embeds don’t need to be built. This may be subject to change.
You can check for full and quick overview of all embed features in Embed reference page. This document will only help understand some of the features from this point.
Fields
Fields are pretty simple. They also have a title(name) and a description(value) just like embeds, but there can be multiple of them and they can be optionally inline. To make a field inline, add true
as a third argument.
Embed embed = new Embed { Title = "Title", Description = "Description. This is not a field." } .AddField("Field #1", "The value of the field") .AddField("Field #2", "This field is inline", inline: true) .AddField("Field #3", "This field is inline too!", inline: true);
It is not mandatory to have either the name or the value of the field. Empty string can be passed to either of them and it will not be visible in the embed. Although passing a null will result in an error by Guilded.NET (because Guilded API does it as well).
Authors and Footers
Embeds have more than descriptions, titles and fields. They can also have an author, which appears at the top, and a footer, which appears at the bottom.
using System; using Guilded.Base.Embeds;
Embed embed = new Embed { Description = "The description of the embed." } .SetAuthor("The name of the author", iconUrl, new Uri("https://guilded.gg/")) .SetFooter("The footer text", iconUrl);
As the name suggests, authors are supposed to represent who made the content. But it isn’t restricted to that. The URL of the author can be used to link either the content or the author’s profile.
Footers provide mostly side information, such as like, comment count, where it was posted, or it could be a replacement for embed author.
Both footer and an author can have an optional icon, although footer cannot hold a URL. But footers can hold timestamps… Well, sort of. Timestamp’s data isn’t defined inside a footer, but it is displayed in the footer.
Embed embed = new Embed { Description = "This embed has a timestamp at the bottom" } .SetTimestamp();
If no argument is passed to SetTimestamp
, UTC current time will be used instead.
Setting side colour
Custom embeds use Color struct to set the colour of the embed. Alpha channel of the embed colour is filtered out, so the transparency of the colour is ignored(if you use Color.Transparent, it will be rendered as white instead). Colour is displayed at the left side of the embed and doesn’t change any other parts of it.
An example using Color.Red as embed colour:
using System; using System.Drawing; using Guilded.Base.Embeds;
Embed embed = new Embed { Title = "Title", Description = "Description", Color = Color.Red };
Colours are not restricted to pre-defined ones. You can create custom colours using Embed.SetColor(int rgba)
, Embed.SetColor(int red, int green, int blue)
or through other means.
Full Embed Example
Embed embed = new Embed { Title = "Title", Url = new Uri("https://guilded.gg/"), Description = "Description", Author = new EmbedAuthor("Author", iconUrl, "https://guilded.gg/"), Footer = new EmbedFooter("Footer", iconUrl), Timestamp = DateTime.Now, Color = Color.Red } .SetImage(iconUrl) .SetThumbnail(iconUrl) .AddField("Name #1", "Value #1", inline: true) .AddField("Name #2", "Value #2", inline: true) .AddField("Name #3", "Value #3");
The end
There is more to custom embeds than mentioned here. Custom embed reference page contains all of the other information necessary, such as how to set a thumbnail or an image. It is recommended to check it out if you want to work with embeds.