diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommands/ApplicationCommandOptionChoice.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommands/ApplicationCommandOptionChoice.cs index 36e5bf39..5da3fb5a 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommands/ApplicationCommandOptionChoice.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommands/ApplicationCommandOptionChoice.cs @@ -21,8 +21,12 @@ namespace Discord get => _name; set { - Preconditions.AtLeast(value.Length, 1, nameof(Name)); - Preconditions.AtMost(value.Length, 100, nameof(Name)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(Name)); + Preconditions.AtMost(value.Length, 100, nameof(Name)); + } + _name = value; } } @@ -38,7 +42,7 @@ namespace Discord get => _value; set { - if (value != null && value is not string && !value.IsNumericType()) + if (value is not null && value is not string && !value.IsNumericType()) throw new ArgumentException($"The value of a choice must be a string or a numeric type! Value: \"{value}\""); _value = value; } diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/ButtonBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/ButtonBuilder.cs index f72a3a5b..f6bfd0b9 100644 --- a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/ButtonBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/ButtonBuilder.cs @@ -24,8 +24,12 @@ public class ButtonBuilder get => _label; set { - Preconditions.AtLeast(value.Length, 1, nameof(Label)); - Preconditions.AtMost(value.Length, MaxButtonLabelLength, nameof(Label)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(Label)); + Preconditions.AtMost(value.Length, MaxButtonLabelLength, nameof(Label)); + } + _label = value; } } @@ -40,8 +44,12 @@ public class ButtonBuilder get => _customId; set { - Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); - Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); + Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); + } + _customId = value; } } diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuBuilder.cs index 95a937d7..75267ac4 100644 --- a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuBuilder.cs @@ -35,8 +35,12 @@ public class SelectMenuBuilder get => _customId; set { - Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); - Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); + Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); + } + _customId = value; } } @@ -63,8 +67,12 @@ public class SelectMenuBuilder get => _placeholder; set { - Preconditions.AtLeast(value.Length, 1, nameof(Placeholder)); - Preconditions.AtMost(value.Length, MaxPlaceholderLength, nameof(Placeholder)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(Placeholder)); + Preconditions.AtMost(value.Length, MaxPlaceholderLength, nameof(Placeholder)); + } + _placeholder = value; } } diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuOptionBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuOptionBuilder.cs index cd62cea9..367cd2a2 100644 --- a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuOptionBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuOptionBuilder.cs @@ -32,8 +32,12 @@ public class SelectMenuOptionBuilder get => _label; set { - Preconditions.AtLeast(value.Length, 1, nameof(Label)); - Preconditions.AtMost(value.Length, MaxSelectLabelLength, nameof(Label)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(Label)); + Preconditions.AtMost(value.Length, MaxSelectLabelLength, nameof(Label)); + } + _label = value; } } @@ -48,8 +52,12 @@ public class SelectMenuOptionBuilder get => _value; set { - Preconditions.AtLeast(value.Length, 1, nameof(Value)); - Preconditions.AtMost(value.Length, MaxSelectValueLength, nameof(Value)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(Value)); + Preconditions.AtMost(value.Length, MaxSelectValueLength, nameof(Value)); + } + _value = value; } } @@ -64,8 +72,12 @@ public class SelectMenuOptionBuilder get => _description; set { - Preconditions.AtLeast(value.Length, 1, nameof(Description)); - Preconditions.AtMost(value.Length, MaxDescriptionLength, nameof(Description)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(Description)); + Preconditions.AtMost(value.Length, MaxDescriptionLength, nameof(Description)); + } + _description = value; } } diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/TextInputBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/TextInputBuilder.cs index c37c39cb..5ca5d199 100644 --- a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/TextInputBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/TextInputBuilder.cs @@ -24,8 +24,12 @@ public class TextInputBuilder get => _customId; set { - Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); - Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); + Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); + } + _customId = value; } } diff --git a/src/Discord.Net.Core/Entities/Interactions/Modals/ModalBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Modals/ModalBuilder.cs index 242c316a..c8424dbb 100644 --- a/src/Discord.Net.Core/Entities/Interactions/Modals/ModalBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/Modals/ModalBuilder.cs @@ -40,8 +40,12 @@ namespace Discord get => _customId; set { - Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); - Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); + if (value is not null) + { + Preconditions.AtLeast(value.Length, 1, nameof(CustomId)); + Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId)); + } + _customId = value; } }