Browse Source

Update EmbedFieldBuilder

Updated Field builder, to allow for "Empty" fields and values.

If you send "_ _" via the discord rest API, it will display as a blank field.

Updated the Value setting to use String.IsNullOrWhiteSpace instead of String.IsNullOrEmpty, because passing a string full of spaces through the API will cause errors as well. However, "_ _" works perfectly.
pull/1132/head
ericmck2000 GitHub 7 years ago
parent
commit
d611e76b5a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions
  1. +12
    -6
      src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs

+ 12
- 6
src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs View File

@@ -239,9 +239,12 @@ namespace Discord
get => _name; get => _name;
set set
{ {
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException($"Field name must not be null, empty or entirely whitespace.", nameof(Name));
if (value.Length > MaxFieldNameLength) throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}.", nameof(Name));
_name = value;
if (string.IsNullOrWhiteSpace(value))
_name = "_ _";
else if (value.Length > MaxFieldNameLength)
throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}.", nameof(Name));
else
_name = value;
} }
} }


@@ -251,9 +254,12 @@ namespace Discord
set set
{ {
var stringValue = value?.ToString(); var stringValue = value?.ToString();
if (string.IsNullOrEmpty(stringValue)) throw new ArgumentException($"Field value must not be null or empty.", nameof(Value));
if (stringValue.Length > MaxFieldValueLength) throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}.", nameof(Value));
_value = stringValue;
if (string.IsNullOrWhiteSpace(stringValue))
_value = "_ _";
else if (stringValue.Length > MaxFieldValueLength)
throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}.", nameof(Value));
else
_value = stringValue;
} }
} }
public bool IsInline { get; set; } public bool IsInline { get; set; }


Loading…
Cancel
Save