@@ -196,7 +196,7 @@ namespace Discord
/// <returns>The current builder.</returns>
public SlashCommandBuilder AddOption(string name, ApplicationCommandOptionType type,
string description, bool? isRequired = null, bool? isDefault = null, bool isAutocomplete = false, double? minValue = null, double? maxValue = null,
List<SlashCommandOptionBuilder> options = null, List<ChannelType> channelTypes = null, params ApplicationCommandOptionChoiceProperties[] choices)
int? minLength = null, int? maxLength = null, List<SlashCommandOptionBuilder> options = null, List<ChannelType> channelTypes = null, params ApplicationCommandOptionChoiceProperties[] choices)
{
Preconditions.Options(name, description);
@@ -222,6 +222,8 @@ namespace Discord
ChannelTypes = channelTypes,
MinValue = minValue,
MaxValue = maxValue,
MinLength = minLength,
MaxLength = maxLength,
};
return AddOption(option);
@@ -354,6 +356,16 @@ namespace Discord
/// </summary>
public double? MaxValue { get; set; }
/// <summary>
/// Gets or sets the minimum allowed length for a string input.
/// </summary>
public int? MinLength { get; set; }
/// <summary>
/// Gets or sets the maximum allowed length for a string input.
/// </summary>
public int? MaxLength { get; set; }
/// <summary>
/// Gets or sets the choices for string and int types for the user to pick from.
/// </summary>
@@ -377,6 +389,7 @@ namespace Discord
{
bool isSubType = Type == ApplicationCommandOptionType.SubCommandGroup;
bool isIntType = Type == ApplicationCommandOptionType.Integer;
bool isStrType = Type == ApplicationCommandOptionType.String;
if (isSubType && (Options == null || !Options.Any()))
throw new InvalidOperationException("SubCommands/SubCommandGroups must have at least one option");
@@ -390,6 +403,12 @@ namespace Discord
if (isIntType && MaxValue != null && MaxValue % 1 != 0)
throw new InvalidOperationException("MaxValue cannot have decimals on Integer command options.");
if(isStrType && MinLength is not null && MinLength < 0)
throw new InvalidOperationException("MinLength cannot be smaller than 0.");
if (isStrType && MaxLength is not null && MaxLength < 1)
throw new InvalidOperationException("MaxLength cannot be smaller than 1.");
return new ApplicationCommandOptionProperties
{
Name = Name,
@@ -404,7 +423,9 @@ namespace Discord
IsAutocomplete = IsAutocomplete,
ChannelTypes = ChannelTypes,
MinValue = MinValue,
MaxValue = MaxValue
MaxValue = MaxValue,
MinLength = MinLength,
MaxLength = MaxLength,
};
}
@@ -425,7 +446,7 @@ namespace Discord
/// <returns>The current builder.</returns>
public SlashCommandOptionBuilder AddOption(string name, ApplicationCommandOptionType type,
string description, bool? isRequired = null, bool isDefault = false, bool isAutocomplete = false, double? minValue = null, double? maxValue = null,
List<SlashCommandOptionBuilder> options = null, List<ChannelType> channelTypes = null, params ApplicationCommandOptionChoiceProperties[] choices)
int? minLength = null, int? maxLength = null, List<SlashCommandOptionBuilder> options = null, List<ChannelType> channelTypes = null, params ApplicationCommandOptionChoiceProperties[] choices)
{
Preconditions.Options(name, description);
@@ -447,6 +468,8 @@ namespace Discord
IsAutocomplete = isAutocomplete,
MinValue = minValue,
MaxValue = maxValue,
MinLength = minLength,
MaxLength = maxLength,
Options = options,
Type = type,
Choices = (choices ?? Array.Empty<ApplicationCommandOptionChoiceProperties>()).ToList(),
@@ -669,6 +692,28 @@ namespace Discord
return this;
}
/// <summary>
/// Sets the current builders min length field.
/// </summary>
/// <param name="length">The value to set.</param>
/// <returns>The current builder.</returns>
public SlashCommandOptionBuilder WithMinLength(int length)
{
MinLength = length;
return this;
}
/// <summary>
/// Sets the current builders max length field.
/// </summary>
/// <param name="lenght">The value to set.</param>
/// <returns>The current builder.</returns>
public SlashCommandOptionBuilder WithMaxLength(int lenght)
{
MaxLength = lenght;
return this;
}
/// <summary>
/// Sets the current type of this builder.
/// </summary>