From 796d6df0c64e48825896bed19f221ccf84a9272c Mon Sep 17 00:00:00 2001 From: ericmck2000 Date: Thu, 23 Aug 2018 09:29:11 -0500 Subject: [PATCH] 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. --- .../Entities/Messages/EmbedBuilder.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs index 32ef060e4..7fd789486 100644 --- a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs +++ b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs @@ -196,6 +196,17 @@ namespace Discord AddField(field); 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) { if (Fields.Count >= MaxFieldCount) @@ -231,6 +242,8 @@ namespace Discord { private string _name; private string _value; + private const string emptyString = "_ _"; + public const int MaxFieldNameLength = 256; public const int MaxFieldValueLength = 1024; @@ -240,7 +253,7 @@ namespace Discord set { if (string.IsNullOrWhiteSpace(value)) - _name = "_ _"; + _name = emptyString; else if (value.Length > MaxFieldNameLength) throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}.", nameof(Name)); else @@ -255,7 +268,7 @@ namespace Discord { var stringValue = value?.ToString(); if (string.IsNullOrWhiteSpace(stringValue)) - _value = "_ _"; + _value = emptyString; else if (stringValue.Length > MaxFieldValueLength) throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}.", nameof(Value)); else