Skip to content

Commit 2b86a79

Browse files
Hampoquinchs
andauthored
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 <[email protected]>
1 parent 11ece4b commit 2b86a79

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public int Length
150150
int authorLength = Author?.Name?.Length ?? 0;
151151
int descriptionLength = Description?.Length ?? 0;
152152
int footerLength = Footer?.Text?.Length ?? 0;
153-
int fieldSum = Fields.Sum(f => f.Name.Length + f.Value.ToString().Length);
153+
int fieldSum = Fields.Sum(f => f.Name.Length + (f.Value?.ToString()?.Length ?? 0));
154154

155155
return titleLength + authorLength + descriptionLength + footerLength + fieldSum;
156156
}

0 commit comments

Comments
 (0)