From 2598890c5da6c4edb0eb3184072cfcc6e35858f4 Mon Sep 17 00:00:00 2001 From: ConnorAU <15099385+ConnorAU@users.noreply.github.com> Date: Sat, 14 Jan 2023 08:40:54 +1000 Subject: [PATCH] Omit username and avatar properties if none provided Prevents error when positng: > AsyncRet: {"username": ["Must be between 1 and 80 in length.", "Username cannot be \"\""]} --- extension/DiscordEmbedBuilder/Discord.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/extension/DiscordEmbedBuilder/Discord.cs b/extension/DiscordEmbedBuilder/Discord.cs index be4ca03..3052d4e 100644 --- a/extension/DiscordEmbedBuilder/Discord.cs +++ b/extension/DiscordEmbedBuilder/Discord.cs @@ -33,13 +33,16 @@ internal static async Task HandleRequest(string[] args) // Bare bones JObject package = new JObject( new JProperty("content", content), - new JProperty("username", username), - new JProperty("avatar_url", avatar), + //new JProperty("username", username), + //new JProperty("avatar_url", avatar), new JProperty("tts", tts) ); - // Build embeds array - List embedList = BuildEmbedList(embeds); + if (username.Length > 0) package.Add(new JProperty("username", username)); + if (avatar.Length > 0) package.Add(new JProperty("avatar_url", avatar)); + + // Build embeds array + List embedList = BuildEmbedList(embeds); JArray embedProperty = new JArray(); for (int i = 0; i < 10; i++) { @@ -61,7 +64,8 @@ internal static async Task HandleRequest(string[] args) APIClient.BaseAddress = new Uri("https://discord.com/api/webhooks/"); APIClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await APIClient.PostAsync(url, new StringContent(JsonConvert.SerializeObject(package), Encoding.UTF8, "application/json")); - await Tools.LogAsyncReply(response.Content); + //Tools.Logger(null,package.ToString()); + await Tools.LogAsyncReply(response.Content); } } catch (Exception e)