DiscordEmbedBuilder doesn't handle URL-encoded spaces properly in some fields
Created by: xSke
When passing an URL containing URL-encoded spaces (%20
) to some EmbedBuilder methods (specifically, WithAuthor
's url
and iconUrl
parameters and WithFooter
's iconUrl
parameter), this will cause a 400 Bad Request on Discord's end when sending said embed. Embed images and thumbnails work fine with the same URL, though.
An example of an URL that triggers this: https://via.placeholder.com/728x90.png?text=Hello%20World
As far as I can tell, this is because DiscordEmbedBuilder.Build()
re-wraps these fields into a new Uri
/DiscordUri
instance by going through DiscordEmbedAuthor
/DiscordEmbedFooter
's property getters, calling .ToString()
, which gets rid of the URL encoding and doesn't pass it on. This is visible in the resulting exception's WebRequest payload:
{
"tts": false,
"embed": {
"thumbnail": {
"url": "https://via.placeholder.com/728x90.png?text=Hello%20World",
"height": 0,
"width": 0
},
"author": {
"name": "Foobar",
"icon_url": "https://via.placeholder.com/728x90.png?text=Hello World"
}
}
}
And the resulting response:
{"code": 50035, "errors": {"embed": {"author": {"icon_url": {"_errors": [{"code": "URL_TYPE_INVALID_URL", "message": "Not a well formed URL."}]}}}}, "message": "Invalid Form Body"}
embed.thumbnail.url
has the URL-encoding passed through correctly, while embed.author.icon_url
doesn't.