Fix a bug in EmbedBuilder.Length when there is an EmbedField with no Value (#2345)

* Update EmbedBuilder.cs

Fixes a bug where 'EmbedBuilder.Length' will throw an exception of type 'System.NullReferenceException' when a field doesn't have a value.

* Update EmbedBuilder.cs

Fixed an incorrect assuption that `Value` was a `string?`

* Update EmbedBuilder.cs

Fixed one more null check

* Update EmbedBuilder.cs

Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com>
This commit is contained in:
Proddy
2022-09-04 07:46:50 +01:00
committed by GitHub
parent 11ece4bf16
commit 2b86a79f70

View File

@@ -150,7 +150,7 @@ namespace Discord
int authorLength = Author?.Name?.Length ?? 0;
int descriptionLength = Description?.Length ?? 0;
int footerLength = Footer?.Text?.Length ?? 0;
int fieldSum = Fields.Sum(f => f.Name.Length + f.Value.ToString().Length);
int fieldSum = Fields.Sum(f => f.Name.Length + (f.Value?.ToString()?.Length ?? 0));
return titleLength + authorLength + descriptionLength + footerLength + fieldSum;
}