Skip to content

Instantly share code, notes, and snippets.

@TomRichter
Last active March 14, 2024 00:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomRichter/03e260616fa90380fbb6cde46ace1c9c to your computer and use it in GitHub Desktop.
Save TomRichter/03e260616fa90380fbb6cde46ace1c9c to your computer and use it in GitHub Desktop.
/// <summary>
/// Displays an Embed with every possible option.
/// </summary>
/// <returns></returns>
[Command("embed")]
[Summary("Displays an Embed.")]
public async Task<RuntimeResult> Embed()
{
Color pink = new Color(255, 0, 255);
string authorAvatarUrl = "https://via.placeholder.com/128/0069C0/FFFFFF/?text=A";
string authorWebsiteUrl = "https://example.com/author";
string titleUrl = "https://example.com/titleurl";
string imageUrl = "https://via.placeholder.com/800x600/C0C000/FFFFFF/?text=IMAGE";
string thumbnailUrl = "https://via.placeholder.com/128/C00000/FFFFFF/?text=THUMB";
string footerIconUrl = "https://via.placeholder.com/128/00C069/FFFFFF/?text=F";
// Make an embed with every option
// Large images are scaled down until the largest dimension is in range
// See embed limitations for character and field count restrictions
// https://discord.com/developers/docs/resources/channel#embed-limits
Embed embed = new EmbedBuilder()
// Colored vertical bar along left edge
// Can use predefined Color structs, or custom RGB and raw int values
.WithColor(pink)
// Appears top left, above title
// Tiny avatar, 24x24px
.WithAuthor("Author Name", authorAvatarUrl, authorWebsiteUrl)
// Appears top left, below author
.WithTitle("Embed Title")
.WithUrl(titleUrl)
// Appears top right, alongside author and title
// Small icon, largest dimension 80px
.WithThumbnailUrl(thumbnailUrl)
// Main embed body
.WithDescription("This is the embed description. It appears as the main body of text.\n\n**Markdown** is allowed here, *even* syntax __Discord__ doesn't ~~normally~~ support like [pretty links](https://example.com/).")
// Fields appear after description
.WithFields(new EmbedFieldBuilder[]
{
// Non-inline fields each get own rows
new EmbedFieldBuilder() { IsInline = false, Name = "Field A", Value = "Value A" },
new EmbedFieldBuilder() { IsInline = false, Name = "Field B", Value = "Value B" },
new EmbedFieldBuilder() { IsInline = false, Name = "Field C", Value = "Value C" },
// Inline fields may share rows
new EmbedFieldBuilder() { IsInline = true, Name = "Field W", Value = "Value W" },
new EmbedFieldBuilder() { IsInline = true, Name = "Field X", Value = "Value X" },
new EmbedFieldBuilder() { IsInline = true, Name = "Field Y", Value = "Value Y" },
new EmbedFieldBuilder() { IsInline = true, Name = "Field Z", Value = "Value Z" },
})
// Appears near bottom, after all content but above footer
// Large image, max width 400px, max height 300px
.WithImageUrl(imageUrl)
// Appears at very bottom, in small color-muted font
// Micro icon, 20x20px
.WithFooter("Footer", footerIconUrl)
.WithCurrentTimestamp()
.Build();
await ReplyAsync(embed: embed);
return CommandResult.FromSuccess();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment