Skip to content

Commit

Permalink
Omit username and avatar properties if none provided
Browse files Browse the repository at this point in the history
Prevents error when positng:
> AsyncRet: {"username": ["Must be between 1 and 80 in length.", "Username cannot be \"\""]}
  • Loading branch information
ConnorAU committed Jan 13, 2023
1 parent 98a2cc1 commit 2598890
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions extension/DiscordEmbedBuilder/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Types.EmbedArray> 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<Types.EmbedArray> embedList = BuildEmbedList(embeds);
JArray embedProperty = new JArray();
for (int i = 0; i < 10; i++)
{
Expand All @@ -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)
Expand Down

0 comments on commit 2598890

Please sign in to comment.