Skip to content

Commit ec0621a

Browse files
authored
fix NRE introduced in 3.17.3 (#3101)
1 parent d27bb49 commit ec0621a

File tree

6 files changed

+61
-21
lines changed

6 files changed

+61
-21
lines changed

src/Discord.Net.Core/Entities/Interactions/ApplicationCommands/ApplicationCommandOptionChoice.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ public string Name
2121
get => _name;
2222
set
2323
{
24-
Preconditions.AtLeast(value.Length, 1, nameof(Name));
25-
Preconditions.AtMost(value.Length, 100, nameof(Name));
24+
if (value is not null)
25+
{
26+
Preconditions.AtLeast(value.Length, 1, nameof(Name));
27+
Preconditions.AtMost(value.Length, 100, nameof(Name));
28+
}
29+
2630
_name = value;
2731
}
2832
}
@@ -38,7 +42,7 @@ public object Value
3842
get => _value;
3943
set
4044
{
41-
if (value != null && value is not string && !value.IsNumericType())
45+
if (value is not null && value is not string && !value.IsNumericType())
4246
throw new ArgumentException($"The value of a choice must be a string or a numeric type! Value: \"{value}\"");
4347
_value = value;
4448
}

src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/ButtonBuilder.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ public string Label
2424
get => _label;
2525
set
2626
{
27-
Preconditions.AtLeast(value.Length, 1, nameof(Label));
28-
Preconditions.AtMost(value.Length, MaxButtonLabelLength, nameof(Label));
27+
if (value is not null)
28+
{
29+
Preconditions.AtLeast(value.Length, 1, nameof(Label));
30+
Preconditions.AtMost(value.Length, MaxButtonLabelLength, nameof(Label));
31+
}
32+
2933
_label = value;
3034
}
3135
}
@@ -40,8 +44,12 @@ public string CustomId
4044
get => _customId;
4145
set
4246
{
43-
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
44-
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
47+
if (value is not null)
48+
{
49+
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
50+
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
51+
}
52+
4553
_customId = value;
4654
}
4755
}

src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuBuilder.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ public string CustomId
3535
get => _customId;
3636
set
3737
{
38-
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
39-
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
38+
if (value is not null)
39+
{
40+
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
41+
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
42+
}
43+
4044
_customId = value;
4145
}
4246
}
@@ -63,8 +67,12 @@ public string Placeholder
6367
get => _placeholder;
6468
set
6569
{
66-
Preconditions.AtLeast(value.Length, 1, nameof(Placeholder));
67-
Preconditions.AtMost(value.Length, MaxPlaceholderLength, nameof(Placeholder));
70+
if (value is not null)
71+
{
72+
Preconditions.AtLeast(value.Length, 1, nameof(Placeholder));
73+
Preconditions.AtMost(value.Length, MaxPlaceholderLength, nameof(Placeholder));
74+
}
75+
6876
_placeholder = value;
6977
}
7078
}

src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/SelectMenuOptionBuilder.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ public string Label
3232
get => _label;
3333
set
3434
{
35-
Preconditions.AtLeast(value.Length, 1, nameof(Label));
36-
Preconditions.AtMost(value.Length, MaxSelectLabelLength, nameof(Label));
35+
if (value is not null)
36+
{
37+
Preconditions.AtLeast(value.Length, 1, nameof(Label));
38+
Preconditions.AtMost(value.Length, MaxSelectLabelLength, nameof(Label));
39+
}
40+
3741
_label = value;
3842
}
3943
}
@@ -48,8 +52,12 @@ public string Value
4852
get => _value;
4953
set
5054
{
51-
Preconditions.AtLeast(value.Length, 1, nameof(Value));
52-
Preconditions.AtMost(value.Length, MaxSelectValueLength, nameof(Value));
55+
if (value is not null)
56+
{
57+
Preconditions.AtLeast(value.Length, 1, nameof(Value));
58+
Preconditions.AtMost(value.Length, MaxSelectValueLength, nameof(Value));
59+
}
60+
5361
_value = value;
5462
}
5563
}
@@ -64,8 +72,12 @@ public string Description
6472
get => _description;
6573
set
6674
{
67-
Preconditions.AtLeast(value.Length, 1, nameof(Description));
68-
Preconditions.AtMost(value.Length, MaxDescriptionLength, nameof(Description));
75+
if (value is not null)
76+
{
77+
Preconditions.AtLeast(value.Length, 1, nameof(Description));
78+
Preconditions.AtMost(value.Length, MaxDescriptionLength, nameof(Description));
79+
}
80+
6981
_description = value;
7082
}
7183
}

src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/TextInputBuilder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ public string CustomId
2424
get => _customId;
2525
set
2626
{
27-
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
28-
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
27+
if (value is not null)
28+
{
29+
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
30+
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
31+
}
32+
2933
_customId = value;
3034
}
3135
}

src/Discord.Net.Core/Entities/Interactions/Modals/ModalBuilder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ public string CustomId
4040
get => _customId;
4141
set
4242
{
43-
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
44-
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
43+
if (value is not null)
44+
{
45+
Preconditions.AtLeast(value.Length, 1, nameof(CustomId));
46+
Preconditions.AtMost(value.Length, ComponentBuilder.MaxCustomIdLength, nameof(CustomId));
47+
}
48+
4549
_customId = value;
4650
}
4751
}

0 commit comments

Comments
 (0)