Browse Source

Added method for "AddBlankField"

Added method to add a blank field. This functionality was quite handy for when I was utilizing discord.js. Allows the embeds to be cleaned up a bit.

I also stored the "Empty string" as a const... To make it easier to update in the future.
pull/1132/head
ericmck2000 GitHub 7 years ago
parent
commit
796d6df0c6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions
  1. +15
    -2
      src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs

+ 15
- 2
src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs View File

@@ -196,6 +196,17 @@ namespace Discord
AddField(field); AddField(field);
return this; return this;
} }
public EmbedBuilder AddBlankField(bool inline = false)
{
var field = new EmbedFieldBuilder()
.WithIsInline(inline)
.WithName(null)
.WithValue(null);
AddField(field);
return this;
}
public EmbedBuilder AddField(EmbedFieldBuilder field) public EmbedBuilder AddField(EmbedFieldBuilder field)
{ {
if (Fields.Count >= MaxFieldCount) if (Fields.Count >= MaxFieldCount)
@@ -231,6 +242,8 @@ namespace Discord
{ {
private string _name; private string _name;
private string _value; private string _value;
private const string emptyString = "_ _";
public const int MaxFieldNameLength = 256; public const int MaxFieldNameLength = 256;
public const int MaxFieldValueLength = 1024; public const int MaxFieldValueLength = 1024;


@@ -240,7 +253,7 @@ namespace Discord
set set
{ {
if (string.IsNullOrWhiteSpace(value)) if (string.IsNullOrWhiteSpace(value))
_name = "_ _";
_name = emptyString;
else if (value.Length > MaxFieldNameLength) else if (value.Length > MaxFieldNameLength)
throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}.", nameof(Name)); throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}.", nameof(Name));
else else
@@ -255,7 +268,7 @@ namespace Discord
{ {
var stringValue = value?.ToString(); var stringValue = value?.ToString();
if (string.IsNullOrWhiteSpace(stringValue)) if (string.IsNullOrWhiteSpace(stringValue))
_value = "_ _";
_value = emptyString;
else if (stringValue.Length > MaxFieldValueLength) else if (stringValue.Length > MaxFieldValueLength)
throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}.", nameof(Value)); throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}.", nameof(Value));
else else


Loading…
Cancel
Save