From 8f6173e7131bf549106b1566b74102884303cdd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Hjorth=C3=B8j?= Date: Wed, 15 Sep 2021 04:06:49 +0200 Subject: [PATCH] Agument error corrections (#149) * Changed arguments to use the variables for errors * Changed name to description on error ArgumentException * Added value?.Length < 1 for Name and Description * Removed old note and added a paragraph * change para to for Value --- .../Entities/Interactions/ApplicationCommandOption.cs | 4 +++- .../Interactions/ApplicationCommandOptionChoice.cs | 7 +++++-- .../Entities/Interactions/SlashCommandBuilder.cs | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs index d33990da1..8d6e22ec1 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs @@ -45,7 +45,9 @@ namespace Discord set { if (value?.Length > 100) - throw new ArgumentException("Name length must be less than or equal to 32"); + throw new ArgumentException("Description length must be less than or equal to 100"); + if (value?.Length < 1) + throw new ArgumentException("Description length must at least 1 character in length"); _description = value; } } diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs index 53332c74b..4a1339dc2 100644 --- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs +++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs @@ -23,14 +23,17 @@ namespace Discord { if(value?.Length > 100) throw new ArgumentException("Name length must be less than or equal to 100"); + if (value?.Length < 1) + throw new ArgumentException("Name length must at least 1 character in length"); _name = value; } } - // Note: discord allows strings & ints as values. how should that be handled? - // should we make this an object and then just type check it? /// /// The value of this choice. + /// + /// Discord only accepts int and string as the input. + /// /// public object Value { diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs index 97d9f7760..0f3ae1d2d 100644 --- a/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs +++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs @@ -296,7 +296,7 @@ namespace Discord set { if (value?.Length > SlashCommandBuilder.MaxNameLength) - throw new ArgumentException("Name length must be less than or equal to 32"); + throw new ArgumentException($"Name length must be less than or equal to {SlashCommandBuilder.MaxNameLength}"); if (value?.Length < 1) throw new ArgumentException("Name length must at least 1 characters in length"); @@ -317,9 +317,9 @@ namespace Discord set { if (value?.Length > SlashCommandBuilder.MaxDescriptionLength) - throw new ArgumentException("Description length must be less than or equal to 100"); + throw new ArgumentException($"Description length must be less than or equal to {SlashCommandBuilder.MaxDescriptionLength}"); if (value?.Length < 1) - throw new ArgumentException("Name length must at least 1 character in length"); + throw new ArgumentException("Description length must at least 1 character in length"); _description = value; }