diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs index 0304120f5..ae45bd310 100644 --- a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs +++ b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Discord.Utils; +using Newtonsoft.Json; namespace Discord { @@ -155,6 +156,45 @@ namespace Discord } } + /// + /// Tries to parse a string into an . + /// + /// The json string to parse. + /// The with populated values. An empty instance if method returns . + /// if was succesfully parsed. if not. + public static bool TryParse(string json, out EmbedBuilder builder) + { + var model = JsonConvert.DeserializeObject(json); + + builder = new EmbedBuilder(); + + if (model is not null) + { + builder = model.ToEmbedBuilder(); + return true; + } + + else + return false; + } + + /// + /// Parses a string into an . + /// + /// The json string to parse. + /// An with populated values from the passed + /// Thrown if the string passed is not valid json. + public static EmbedBuilder Parse(string json) + { + var model = JsonConvert.DeserializeObject(json); + + if (model is not null) + return model.ToEmbedBuilder(); + + else + throw new JsonSerializationException("The passed json string was not able to be parsed to an embed."); + } + /// /// Sets the title of an . ///