You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EmbedBuilder.Overwrites.md 1.9 kB

7 years ago
7 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ---
  2. uid: Discord.EmbedBuilder
  3. seealso:
  4. - linkId: Discord.EmbedFooterBuilder
  5. - linkId: Discord.EmbedAuthorBuilder
  6. - linkId: Discord.EmbedFieldBuilder
  7. remarks: *content
  8. ---
  9. This builder class is used to build an @Discord.Embed (rich embed)
  10. object that will be ready to be sent via @Discord.IMessageChannel.SendMessageAsync*
  11. after @Discord.EmbedBuilder.Build* is called.
  12. ---
  13. uid: Discord.EmbedBuilder
  14. example: [*content]
  15. ---
  16. #### Basic Usage
  17. The example below builds an embed and sends it to the chat using the
  18. command system.
  19. ```cs
  20. [Command("embed")]
  21. public async Task SendRichEmbedAsync()
  22. {
  23. var embed = new EmbedBuilder
  24. {
  25. // Embed property can be set within object initializer
  26. Title = "Hello world!"
  27. Description = "I am a description set by initializer."
  28. };
  29. // Or with methods
  30. embed.AddField("Field title",
  31. "Field value. I also support [hyperlink markdown](https://example.com)!")
  32. .WithAuthor(Context.Client.CurrentUser)
  33. .WithFooter(footer => footer.Text = "I am a footer.")
  34. .WithColor(Color.Blue)
  35. .WithTitle("I overwrote \"Hello world!\"")
  36. .WithDescription("I am a description.")
  37. .WithUrl("https://example.com")
  38. .WithCurrentTimestamp()
  39. .Build();
  40. await ReplyAsync(embed: embed);
  41. }
  42. ```
  43. ![Embed Example](images/embed-example.png)
  44. #### Usage with Local Images
  45. The example below sends an image and has the image embedded in the rich
  46. embed. See @Discord.IMessageChannel.SendFileAsync* for more information
  47. about uploading a file or image.
  48. ```cs
  49. [Command("embedimage")]
  50. public async Task SendEmbedWithImageAsync()
  51. {
  52. var fileName = "image.png";
  53. var embed = new EmbedBuilder()
  54. {
  55. ImageUrl = $"attachment://{fileName}"
  56. }.Build();
  57. await Context.Channel.SendFileAsync(fileName, embed: embed);
  58. }
  59. ```