Browse Source

feat: AddOptions no longer has an uneeded restriction, added AddOptions to SlashCommandOptionBuilder (#2338)

tags/3.7.2
CottageDwellingCat GitHub 3 years ago
parent
commit
3a37f8914c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 5 deletions
  1. +22
    -5
      src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs

+ 22
- 5
src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs View File

@@ -255,9 +255,6 @@ namespace Discord
if (options == null) if (options == null)
throw new ArgumentNullException(nameof(options), "Options cannot be null!"); throw new ArgumentNullException(nameof(options), "Options cannot be null!");


if (options.Length == 0)
throw new ArgumentException("Options cannot be empty!", nameof(options));

Options ??= new List<SlashCommandOptionBuilder>(); Options ??= new List<SlashCommandOptionBuilder>();


if (Options.Count + options.Length > MaxOptionsCount) if (Options.Count + options.Length > MaxOptionsCount)
@@ -409,7 +406,7 @@ namespace Discord
MinValue = MinValue, MinValue = MinValue,
MaxValue = MaxValue MaxValue = MaxValue
}; };
}
}


/// <summary> /// <summary>
/// Adds an option to the current slash command. /// Adds an option to the current slash command.
@@ -477,6 +474,26 @@ namespace Discord
return this; return this;
} }


/// <summary>
/// Adds a collection of options to the current option.
/// </summary>
/// <param name="options">The collection of options to add.</param>
/// <returns>The current builder.</returns>
public SlashCommandOptionBuilder AddOptions(params SlashCommandOptionBuilder[] options)
{
if (options == null)
throw new ArgumentNullException(nameof(options), "Options cannot be null!");

if ((Options?.Count ?? 0) + options.Length > SlashCommandBuilder.MaxOptionsCount)
throw new ArgumentOutOfRangeException(nameof(options), $"There can only be {SlashCommandBuilder.MaxOptionsCount} options per sub command group!");

foreach (var option in options)
Preconditions.Options(option.Name, option.Description);

Options.AddRange(options);
return this;
}

/// <summary> /// <summary>
/// Adds a choice to the current option. /// Adds a choice to the current option.
/// </summary> /// </summary>
@@ -640,7 +657,7 @@ namespace Discord
MinValue = value; MinValue = value;
return this; return this;
} }
/// <summary> /// <summary>
/// Sets the current builders max value field. /// Sets the current builders max value field.
/// </summary> /// </summary>


Loading…
Cancel
Save