diff --git a/src/Disqord.Core/Models/Interactions/Components/ComponentJsonModel.cs b/src/Disqord.Core/Models/Interactions/Components/ComponentJsonModel.cs index a4e33ad32..f98c4b4ad 100644 --- a/src/Disqord.Core/Models/Interactions/Components/ComponentJsonModel.cs +++ b/src/Disqord.Core/Models/Interactions/Components/ComponentJsonModel.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Disqord.Serialization.Json; using Qommon; @@ -140,6 +141,27 @@ protected override void OnValidate() if (MinValues.HasValue && MaxValues.HasValue) Guard.IsLessThanOrEqualTo(MinValues.Value, MaxValues.Value); + OptionalGuard.CheckValue(DefaultValues, defaultValues => + { + Guard.IsBetween(defaultValues.Length, MinValues.GetValueOrDefault(Discord.Limits.Component.Selection.MinMinimumSelectedOptions), MaxValues.GetValueOrDefault(Discord.Limits.Component.Selection.MaxMaximumSelectedOptions)); + + switch (Type) + { + case ComponentType.UserSelection: + Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.User)); + break; + case ComponentType.RoleSelection: + Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.Role)); + break; + case ComponentType.MentionableSelection: + Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.User || x.Type == DefaultSelectionValueType.Role)); + break; + case ComponentType.ChannelSelection: + Guard.IsTrue(defaultValues.All(x => x.Type == DefaultSelectionValueType.Channel)); + break; + } + }); + break; } case ComponentType.TextInput: