From 5e3f119e95937829dddaf32b3c83d3f27cc13159 Mon Sep 17 00:00:00 2001
From: Nikon <47792796+INikonI@users.noreply.github.com>
Date: Fri, 23 Jul 2021 08:58:59 +0500
Subject: [PATCH] Improvements builders docs and adding/renaming
methods/constructors and some fixes (#50)
* Refactor emojis/emotes & SelectMenu
* Update Emoji.cs
* Continue emoji refactor
* Remove WithLabel from example of SelectMenuBuilder
* Remove EmojiUtils and move it stuff to Emoji
* Revert 0fbf1000daf5d2afc130797a3ee2421b120beaa2
* Revert "Update Emoji.cs" and add Parse method
This reverts commit f297dcfc4320c55ba7108b8e7ef9fa5ad35cd3bc.
* Partial revert 3c27ab36c9a0603ac9b1a7819d1be6bb37d7213a
* Builders docs improve and add/rename methods/ctors
* Update Discord.Net.Core.xml
* Add SelectMenuBuilder.AddOption overload
* Docs fix
* Update Discord.Net.Core.xml
* corrections of unnecessary docs
* corrections of unnecessary docs!
* Fix docs and exceptions
---
src/Discord.Net.Core/Discord.Net.Core.xml | 155 ++++++---
.../Message Components/ComponentBuilder.cs | 307 +++++++++++-------
.../Entities/Messages/EmbedBuilder.cs | 28 +-
3 files changed, 321 insertions(+), 169 deletions(-)
diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml
index 76a02fffb..a72df4e09 100644
--- a/src/Discord.Net.Core/Discord.Net.Core.xml
+++ b/src/Discord.Net.Core/Discord.Net.Core.xml
@@ -4371,11 +4371,13 @@
Gets or sets the Action Rows for this Component Builder.
+ cannot be null.
+ count exceeds .
- Adds a to the first row, if the first row cannot
- accept the component then it will add it to a row that can
+ Adds a to the at the specific row.
+ If the row cannot accept the component then it will add it to a row that can.
The label of the menu.
The custom id of the menu.
@@ -4387,20 +4389,15 @@
The row to add the menu to.
-
-
- Adds a to the first row, if the first row cannot
- accept the component then it will add it to a row that can
-
- The menu to add
- The current builder.
-
- Adds a to the current builder at the specific row.
+ Adds a to the at the specific row.
+ If the row cannot accept the component then it will add it to a row that can.
The menu to add.
The row to attempt to add this component on.
+ There is no more row to add a menu.
+ must be less than .
The current builder.
@@ -4416,26 +4413,22 @@
The row the button should be placed on.
The current builder.
-
-
- Adds a button to the first row.
-
- The button to add to the first row.
- The current builder.
-
- Adds a button to the specified row.
+ Adds a to the at the specific row.
+ If the row cannot accept the component then it will add it to a row that can.
The button to add.
The row to add the button.
+ There is no more row to add a menu.
+ must be less than .
The current builder.
Builds this builder into a used to send your components.
- A that can be sent with
+ A that can be sent with .
@@ -4451,19 +4444,23 @@
Gets or sets the components inside this row.
+ cannot be null.
+ count exceeds .
Adds a list of components to the current row.
The list of components to add.
+
The current builder.
-
+
Adds a component at the end of the current row.
The component to add.
+ Components count reached
The current builder.
@@ -4471,8 +4468,6 @@
Builds the current builder to a that can be used within a
A that can be used within a
- cannot be null.
- There must be at least 1 component in a row.
@@ -4483,11 +4478,13 @@
Gets or sets the label of the current button.
+ length exceeds .
Gets or sets the custom id of the current button.
+ length exceeds
@@ -4509,6 +4506,27 @@
Gets or sets whether the current button is disabled.
+
+
+ Creates a new instance of a .
+
+
+
+
+ Creates a new instance of a .
+
+ The label to use on the newly created link button.
+ The url of this button.
+ The custom ID of this button
+ The custom ID of this button
+ The emote of this button
+ Disabled this button or not
+
+
+
+ Creates a new instance of a from instance of a .
+
+
Creates a button with the style.
@@ -4554,6 +4572,7 @@
Sets the current buttons label to the specified text.
The text for the label
+
The current builder.
@@ -4582,6 +4601,7 @@
Sets the custom id of the current button.
The id to use for the current button.
+
The current builder.
@@ -4596,8 +4616,8 @@
Builds this builder into a to be used in a .
A to be used in a .
- A button cannot contain a URL and a CustomId.
- A button must have an Emote or a label.
+ A button cannot contain a and a .
+ A button must have an or a .
@@ -4623,26 +4643,32 @@
Gets or sets the custom id of the current select menu.
+ length exceeds .
Gets or sets the placeholder text of the current select menu.
+ length exceeds .
Gets or sets the minimum values of the current select menu.
+ exceeds .
Gets or sets the maximum values of the current select menu.
+ exceeds .
Gets or sets a collection of for this current select menu.
+ count exceeds .
+ is null.
@@ -4654,18 +4680,28 @@
Creates a new instance of a .
-
+
+
+ Creates a new instance of a from instance of .
+
+
+
Creates a new instance of a .
The custom id of this select menu.
The options for this select menu.
+ The placeholder of this select menu.
+ The max values of this select menu.
+ The min values of this select menu.
+ Disabled this select menu or not.
Sets the field CustomId.
The value to set the field CustomId to.
+
The current builder.
@@ -4675,6 +4711,7 @@
Sets the field placeholder.
The value to set the field placeholder to.
+
The current builder.
@@ -4684,6 +4721,7 @@
Sets the field minValues.
The value to set the field minValues to.
+
The current builder.
@@ -4693,6 +4731,7 @@
Sets the field maxValues.
The value to set the field maxValues to.
+
The current builder.
@@ -4702,6 +4741,31 @@
Sets the field options.
The value to set the field options to.
+
+
+ The current builder.
+
+
+
+
+ Add one option to menu options.
+
+ The option builder class containing the option properties.
+ Options count reached .
+
+ The current builder.
+
+
+
+
+ Add one option to menu options.
+
+ The label for this option.
+ The value of this option.
+ The description of this option.
+ The emote of this option.
+ Render this option as selected by default or not.
+ Options count reached .
The current builder.
@@ -4735,16 +4799,19 @@
Gets or sets the label of the current select menu.
+ length exceeds
Gets or sets the custom id of the current select menu.
+ length exceeds .
Gets or sets this menu options description.
+ length exceeds .
@@ -4761,18 +4828,22 @@
Creates a new instance of a .
-
+
Creates a new instance of a .
The label for this option.
The value of this option.
+ The description of this option.
+ The emote of this option.
+ Render this option as selected by default or not.
Sets the field label.
The value to set the field label to.
+
The current builder.
@@ -4782,6 +4853,7 @@
Sets the field value.
The value to set the field value to.
+
The current builder.
@@ -4791,6 +4863,7 @@
Sets the field description.
The value to set the field description to.
+
The current builder.
@@ -5568,23 +5641,23 @@
-
- Returns the maximum number of fields allowed by Discord.
+
+ Returns the maximum number of fields allowed by Discord.
-
- Returns the maximum length of title allowed by Discord.
+
+ Returns the maximum length of title allowed by Discord.
-
- Returns the maximum length of description allowed by Discord.
+
+ Returns the maximum length of description allowed by Discord.
-
- Returns the maximum length of total characters allowed by Discord.
+
+ Returns the maximum length of total characters allowed by Discord.
@@ -5618,9 +5691,9 @@
Gets or sets the list of of an .
- An embed builder's fields collection is set to
+ An embed builder's fields collection is set to
null.
- Description length exceeds .
+ Fields count exceeds .
The list of existing .
@@ -5661,7 +5734,7 @@
Gets the total length of all embed properties.
- The combined length of , , ,
+ The combined length of , , ,
, , and .
@@ -5675,7 +5748,7 @@
-
+
Sets the description of an .
The description to be set.
@@ -5684,7 +5757,7 @@
-
+
Sets the URL of an .
The URL to be set.
@@ -5693,7 +5766,7 @@
-
+
Sets the thumbnail URL of an .
The thumbnail URL to be set.
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs
index 5a5145a27..89bd6598a 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs
@@ -27,6 +27,8 @@ namespace Discord
///
/// Gets or sets the Action Rows for this Component Builder.
///
+ /// cannot be null.
+ /// count exceeds .
public List ActionRows
{
get => _actionRows;
@@ -43,8 +45,8 @@ namespace Discord
private List _actionRows { get; set; }
///
- /// Adds a to the first row, if the first row cannot
- /// accept the component then it will add it to a row that can
+ /// Adds a to the at the specific row.
+ /// If the row cannot accept the component then it will add it to a row that can.
///
/// The label of the menu.
/// The custom id of the menu.
@@ -69,38 +71,34 @@ namespace Discord
}
///
- /// Adds a to the first row, if the first row cannot
- /// accept the component then it will add it to a row that can
- ///
- /// The menu to add
- /// The current builder.
- public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu)
- => WithSelectMenu(menu, 0);
-
- ///
- /// Adds a to the current builder at the specific row.
+ /// Adds a to the at the specific row.
+ /// If the row cannot accept the component then it will add it to a row that can.
///
/// The menu to add.
/// The row to attempt to add this component on.
+ /// There is no more row to add a menu.
+ /// must be less than .
/// The current builder.
- public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row)
+ public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row = 0)
{
- Preconditions.LessThan(row, 5, nameof(row));
+ Preconditions.LessThan(row, MaxActionRowCount, nameof(row));
var builtMenu = menu.Build();
if (_actionRows == null)
{
- _actionRows = new List();
- _actionRows.Add(new ActionRowBuilder().WithComponent(builtMenu));
+ _actionRows = new List
+ {
+ new ActionRowBuilder().AddComponent(builtMenu)
+ };
}
else
{
if (_actionRows.Count == row)
- _actionRows.Add(new ActionRowBuilder().WithComponent(builtMenu));
+ _actionRows.Add(new ActionRowBuilder().AddComponent(builtMenu));
else
{
- ActionRowBuilder actionRow = null;
+ ActionRowBuilder actionRow;
if (_actionRows.Count > row)
actionRow = _actionRows.ElementAt(row);
else
@@ -110,11 +108,11 @@ namespace Discord
}
if (actionRow.CanTakeComponent(builtMenu))
- actionRow.WithComponent(builtMenu);
- else if (row < 5)
+ actionRow.AddComponent(builtMenu);
+ else if (row < MaxActionRowCount)
WithSelectMenu(menu, row + 1);
else
- throw new ArgumentOutOfRangeException($"There is no more room to add a {nameof(builtMenu)}");
+ throw new InvalidOperationException($"There is no more row to add a {nameof(builtMenu)}");
}
}
@@ -153,37 +151,32 @@ namespace Discord
}
///
- /// Adds a button to the first row.
- ///
- /// The button to add to the first row.
- /// The current builder.
- public ComponentBuilder WithButton(ButtonBuilder button)
- => this.WithButton(button, 0);
-
- ///
- /// Adds a button to the specified row.
+ /// Adds a to the at the specific row.
+ /// If the row cannot accept the component then it will add it to a row that can.
///
/// The button to add.
/// The row to add the button.
+ /// There is no more row to add a menu.
+ /// must be less than .
/// The current builder.
public ComponentBuilder WithButton(ButtonBuilder button, int row = 0)
{
- Preconditions.LessThan(row, 5, nameof(row));
+ Preconditions.LessThan(row, MaxActionRowCount, nameof(row));
var builtButton = button.Build();
if (_actionRows == null)
{
_actionRows = new List();
- _actionRows.Add(new ActionRowBuilder().WithComponent(builtButton));
+ _actionRows.Add(new ActionRowBuilder().AddComponent(builtButton));
}
else
{
if (_actionRows.Count == row)
- _actionRows.Add(new ActionRowBuilder().WithComponent(builtButton));
+ _actionRows.Add(new ActionRowBuilder().AddComponent(builtButton));
else
{
- ActionRowBuilder actionRow = null;
+ ActionRowBuilder actionRow;
if(_actionRows.Count > row)
actionRow = _actionRows.ElementAt(row);
else
@@ -193,11 +186,11 @@ namespace Discord
}
if (actionRow.CanTakeComponent(builtButton))
- actionRow.WithComponent(builtButton);
- else if (row < 5)
+ actionRow.AddComponent(builtButton);
+ else if (row < MaxActionRowCount)
WithButton(button, row + 1);
else
- throw new ArgumentOutOfRangeException($"There is no more room to add a {nameof(button)}");
+ throw new InvalidOperationException($"There is no more row to add a {nameof(button)}");
}
}
@@ -207,7 +200,7 @@ namespace Discord
///
/// Builds this builder into a used to send your components.
///
- /// A that can be sent with
+ /// A that can be sent with .
public MessageComponent Build()
{
if (this._actionRows != null)
@@ -230,14 +223,22 @@ namespace Discord
///
/// Gets or sets the components inside this row.
///
+ /// cannot be null.
+ /// count exceeds .
public List Components
{
get => _components;
set
{
- if (value != null)
- if (value.Count > MaxChildCount)
- throw new ArgumentException(message: $"Action row can only contain {MaxChildCount} child components!", paramName: nameof(Components));
+ if (value == null)
+ throw new ArgumentNullException(message: "Action row components cannot be null!", paramName: nameof(Components));
+
+ if (value.Count <= 0)
+ throw new ArgumentException(message: "There must be at least 1 component in a row", paramName: nameof(Components));
+
+ if (value.Count > MaxChildCount)
+ throw new ArgumentException(message: $"Action row can only contain {MaxChildCount} child components!", paramName: nameof(Components));
+
_components = value;
}
}
@@ -248,6 +249,7 @@ namespace Discord
/// Adds a list of components to the current row.
///
/// The list of components to add.
+ ///
/// The current builder.
public ActionRowBuilder WithComponents(List components)
{
@@ -259,14 +261,14 @@ namespace Discord
/// Adds a component at the end of the current row.
///
/// The component to add.
+ /// Components count reached
/// The current builder.
- public ActionRowBuilder WithComponent(IMessageComponent component)
+ public ActionRowBuilder AddComponent(IMessageComponent component)
{
- if (this.Components == null)
- this.Components = new List();
+ if (this.Components.Count >= MaxChildCount)
+ throw new InvalidOperationException($"Components count reached {MaxChildCount}");
this.Components.Add(component);
-
return this;
}
@@ -274,16 +276,8 @@ namespace Discord
/// Builds the current builder to a that can be used within a
///
/// A that can be used within a
- /// cannot be null.
- /// There must be at least 1 component in a row.
public ActionRowComponent Build()
{
- if (this.Components == null)
- throw new ArgumentNullException($"{nameof(Components)} cannot be null!");
-
- if (this.Components.Count == 0)
- throw new ArgumentException("There must be at least 1 component in a row");
-
return new ActionRowComponent(this._components);
}
@@ -314,14 +308,14 @@ namespace Discord
///
/// Gets or sets the label of the current button.
///
+ /// length exceeds .
public string Label
{
get => _label;
set
{
- if (value != null)
- if (value.Length > ComponentBuilder.MaxLabelLength)
- throw new ArgumentException(message: $"Button label must be {ComponentBuilder.MaxLabelLength} characters or less!", paramName: nameof(Label));
+ if (value != null && value.Length > ComponentBuilder.MaxLabelLength)
+ throw new ArgumentException(message: $"Button label must be {ComponentBuilder.MaxLabelLength} characters or less!", paramName: nameof(Label));
_label = value;
}
@@ -330,14 +324,14 @@ namespace Discord
///
/// Gets or sets the custom id of the current button.
///
+ /// length exceeds
public string CustomId
{
get => _customId;
set
{
- if (value != null)
- if (value.Length > ComponentBuilder.MaxCustomIdLength)
- throw new ArgumentException(message: $"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
+ if (value != null && value.Length > ComponentBuilder.MaxCustomIdLength)
+ throw new ArgumentException(message: $"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
_customId = value;
}
}
@@ -366,6 +360,43 @@ namespace Discord
private string _label;
private string _customId;
+ ///
+ /// Creates a new instance of a .
+ ///
+ public ButtonBuilder() { }
+
+ ///
+ /// Creates a new instance of a .
+ ///
+ /// The label to use on the newly created link button.
+ /// The url of this button.
+ /// The custom ID of this button
+ /// The custom ID of this button
+ /// The emote of this button
+ /// Disabled this button or not
+ public ButtonBuilder(string label, string customId, ButtonStyle style = ButtonStyle.Primary, string url = null, IEmote emote = null, bool disabled = false)
+ {
+ this.CustomId = customId;
+ this.Style = style;
+ this.Url = url;
+ this.Label = label;
+ this.Disabled = disabled;
+ this.Emote = emote;
+ }
+
+ ///
+ /// Creates a new instance of a from instance of a .
+ ///
+ public ButtonBuilder(ButtonComponent button)
+ {
+ this.CustomId = button.CustomId;
+ this.Style = button.Style;
+ this.Url = button.Url;
+ this.Label = button.Label;
+ this.Disabled = button.Disabled;
+ this.Emote = button.Emote;
+ }
+
///
/// Creates a button with the style.
///
@@ -373,14 +404,7 @@ namespace Discord
/// The url for this link button to go to.
/// A builder with the newly created button.
public static ButtonBuilder CreateLinkButton(string label, string url)
- {
- var builder = new ButtonBuilder()
- .WithStyle(ButtonStyle.Link)
- .WithUrl(url)
- .WithLabel(label);
-
- return builder;
- }
+ => new ButtonBuilder(label, null, ButtonStyle.Link, url);
///
/// Creates a button with the style.
@@ -389,14 +413,7 @@ namespace Discord
/// The custom id for this danger button.
/// A builder with the newly created button.
public static ButtonBuilder CreateDangerButton(string label, string customId)
- {
- var builder = new ButtonBuilder()
- .WithStyle(ButtonStyle.Danger)
- .WithCustomId(customId)
- .WithLabel(label);
-
- return builder;
- }
+ => new ButtonBuilder(label, customId, ButtonStyle.Danger);
///
/// Creates a button with the style.
@@ -405,14 +422,7 @@ namespace Discord
/// The custom id for this primary button.
/// A builder with the newly created button.
public static ButtonBuilder CreatePrimaryButton(string label, string customId)
- {
- var builder = new ButtonBuilder()
- .WithStyle(ButtonStyle.Primary)
- .WithCustomId(customId)
- .WithLabel(label);
-
- return builder;
- }
+ => new ButtonBuilder(label, customId);
///
/// Creates a button with the style.
@@ -421,14 +431,7 @@ namespace Discord
/// The custom id for this secondary button.
/// A builder with the newly created button.
public static ButtonBuilder CreateSecondaryButton(string label, string customId)
- {
- var builder = new ButtonBuilder()
- .WithStyle(ButtonStyle.Secondary)
- .WithCustomId(customId)
- .WithLabel(label);
-
- return builder;
- }
+ => new ButtonBuilder(label, customId, ButtonStyle.Secondary);
///
/// Creates a button with the style.
@@ -437,19 +440,13 @@ namespace Discord
/// The custom id for this success button.
/// A builder with the newly created button.
public static ButtonBuilder CreateSuccessButton(string label, string customId)
- {
- var builder = new ButtonBuilder()
- .WithStyle(ButtonStyle.Success)
- .WithCustomId(customId)
- .WithLabel(label);
-
- return builder;
- }
+ => new ButtonBuilder(label, customId, ButtonStyle.Success);
///
/// Sets the current buttons label to the specified text.
///
/// The text for the label
+ ///
/// The current builder.
public ButtonBuilder WithLabel(string label)
{
@@ -494,6 +491,7 @@ namespace Discord
/// Sets the custom id of the current button.
///
/// The id to use for the current button.
+ ///
/// The current builder.
public ButtonBuilder WithCustomId(string id)
{
@@ -516,15 +514,15 @@ namespace Discord
/// Builds this builder into a to be used in a .
///
/// A to be used in a .
- /// A button cannot contain a URL and a CustomId.
- /// A button must have an Emote or a label.
+ /// A button cannot contain a and a .
+ /// A button must have an or a .
public ButtonComponent Build()
{
if (string.IsNullOrEmpty(this.Label) && this.Emote == null)
- throw new ArgumentException("A button must have an Emote or a label!");
+ throw new InvalidOperationException("A button must have an Emote or a label!");
if (!string.IsNullOrEmpty(this.Url) && !string.IsNullOrEmpty(this.CustomId))
- throw new InvalidOperationException("A button cannot contain a URL and a CustomId");
+ throw new InvalidOperationException("A button cannot contain a URL and a CustomId!");
if (this.Style == ButtonStyle.Link && !string.IsNullOrEmpty(this.CustomId))
this.CustomId = null;
@@ -559,14 +557,14 @@ namespace Discord
///
/// Gets or sets the custom id of the current select menu.
///
+ /// length exceeds .
public string CustomId
{
get => _customId;
set
{
- if (value != null)
- if (value.Length > ComponentBuilder.MaxCustomIdLength)
- throw new ArgumentException(message: $"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
+ if (value != null && value.Length > ComponentBuilder.MaxCustomIdLength)
+ throw new ArgumentException(message: $"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
_customId = value;
}
}
@@ -574,6 +572,7 @@ namespace Discord
///
/// Gets or sets the placeholder text of the current select menu.
///
+ /// length exceeds .
public string Placeholder
{
get => _placeholder;
@@ -589,6 +588,7 @@ namespace Discord
///
/// Gets or sets the minimum values of the current select menu.
///
+ /// exceeds .
public int MinValues
{
get => _minValues;
@@ -602,6 +602,7 @@ namespace Discord
///
/// Gets or sets the maximum values of the current select menu.
///
+ /// exceeds .
public int MaxValues
{
get => _maxValues;
@@ -615,6 +616,8 @@ namespace Discord
///
/// Gets or sets a collection of for this current select menu.
///
+ /// count exceeds .
+ /// is null.
public List Options
{
get => _options;
@@ -622,6 +625,8 @@ namespace Discord
{
if (value != null)
Preconditions.LessThan(value.Count, MaxOptionCount, nameof(Options));
+ else
+ throw new ArgumentNullException(nameof(value));
_options = value;
}
@@ -632,7 +637,7 @@ namespace Discord
///
public bool Disabled { get; set; }
- private List _options;
+ private List _options = new List();
private int _minValues = 1;
private int _maxValues = 1;
private string _placeholder;
@@ -643,21 +648,45 @@ namespace Discord
///
public SelectMenuBuilder() { }
+ ///
+ /// Creates a new instance of a from instance of .
+ ///
+ public SelectMenuBuilder(SelectMenu selectMenu)
+ {
+ this.Placeholder = selectMenu.Placeholder;
+ this.CustomId = selectMenu.Placeholder;
+ this.MaxValues = selectMenu.MaxValues;
+ this.MinValues = selectMenu.MinValues;
+ this.Disabled = selectMenu.Disabled;
+ this.Options = selectMenu.Options?
+ .Select(x => new SelectMenuOptionBuilder(x.Label, x.Value, x.Description, x.Emote, x.Default))
+ .ToList();
+ }
+
///
/// Creates a new instance of a .
///
/// The custom id of this select menu.
/// The options for this select menu.
- public SelectMenuBuilder(string customId, List options)
+ /// The placeholder of this select menu.
+ /// The max values of this select menu.
+ /// The min values of this select menu.
+ /// Disabled this select menu or not.
+ public SelectMenuBuilder(string customId, List options, string placeholder = null, int maxValues = 1, int minValues = 1, bool disabled = false)
{
this.CustomId = customId;
this.Options = options;
+ this.Placeholder = placeholder;
+ this.Disabled = disabled;
+ this.MaxValues = maxValues;
+ this.MinValues = minValues;
}
///
/// Sets the field CustomId.
///
/// The value to set the field CustomId to.
+ ///
///
/// The current builder.
///
@@ -671,6 +700,7 @@ namespace Discord
/// Sets the field placeholder.
///
/// The value to set the field placeholder to.
+ ///
///
/// The current builder.
///
@@ -684,6 +714,7 @@ namespace Discord
/// Sets the field minValues.
///
/// The value to set the field minValues to.
+ ///
///
/// The current builder.
///
@@ -697,6 +728,7 @@ namespace Discord
/// Sets the field maxValues.
///
/// The value to set the field maxValues to.
+ ///
///
/// The current builder.
///
@@ -710,6 +742,7 @@ namespace Discord
/// Sets the field options.
///
/// The value to set the field options to.
+ ///
///
/// The current builder.
///
@@ -719,6 +752,41 @@ namespace Discord
return this;
}
+ ///
+ /// Add one option to menu options.
+ ///
+ /// The option builder class containing the option properties.
+ /// Options count reached .
+ ///
+ /// The current builder.
+ ///
+ public SelectMenuBuilder AddOption(SelectMenuOptionBuilder option)
+ {
+ if (this.Options.Count >= MaxOptionCount)
+ throw new InvalidOperationException($"Options count reached {MaxOptionCount}.");
+
+ this.Options.Add(option);
+ return this;
+ }
+
+ ///
+ /// Add one option to menu options.
+ ///
+ /// The label for this option.
+ /// The value of this option.
+ /// The description of this option.
+ /// The emote of this option.
+ /// Render this option as selected by default or not.
+ /// Options count reached .
+ ///
+ /// The current builder.
+ ///
+ public SelectMenuBuilder AddOption(string label, string value, string description = null, IEmote emote = null, bool? @default = null)
+ {
+ AddOption(new SelectMenuOptionBuilder(label, value, description, emote, @default));
+ return this;
+ }
+
///
/// Sets whether the current menu is disabled.
///
@@ -757,6 +825,7 @@ namespace Discord
///
/// Gets or sets the label of the current select menu.
///
+ /// length exceeds
public string Label
{
get => _label;
@@ -773,14 +842,14 @@ namespace Discord
///
/// Gets or sets the custom id of the current select menu.
///
+ /// length exceeds .
public string Value
{
get => _value;
set
{
- if (value != null)
- if (value.Length > ComponentBuilder.MaxCustomIdLength)
- throw new ArgumentException(message: $"Value must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(Value));
+ if (value != null && value.Length > ComponentBuilder.MaxCustomIdLength)
+ throw new ArgumentException(message: $"Value must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(Value));
_value = value;
}
}
@@ -788,13 +857,14 @@ namespace Discord
///
/// Gets or sets this menu options description.
///
+ /// length exceeds .
public string Description
{
get => _description;
set
{
- if (value != null)
- Preconditions.LessThan(value.Length, MaxDescriptionLength, nameof(Description));
+ if (value != null && value.Length > MaxDescriptionLength)
+ throw new ArgumentException($"Description must be {MaxDescriptionLength} characters or less!", nameof(Description));
_description = value;
}
@@ -824,16 +894,23 @@ namespace Discord
///
/// The label for this option.
/// The value of this option.
- public SelectMenuOptionBuilder(string label, string value)
+ /// The description of this option.
+ /// The emote of this option.
+ /// Render this option as selected by default or not.
+ public SelectMenuOptionBuilder(string label, string value, string description = null, IEmote emote = null, bool? @default = null)
{
this.Label = label;
this.Value = value;
+ this.Description = description;
+ this.Emote = emote;
+ this.Default = @default;
}
///
/// Sets the field label.
///
/// The value to set the field label to.
+ ///
///
/// The current builder.
///
@@ -847,6 +924,7 @@ namespace Discord
/// Sets the field value.
///
/// The value to set the field value to.
+ ///
///
/// The current builder.
///
@@ -860,6 +938,7 @@ namespace Discord
/// Sets the field description.
///
/// The value to set the field description to.
+ ///
///
/// The current builder.
///
diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs
index 89aaf5fde..2ac6efa6b 100644
--- a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs
+++ b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs
@@ -16,20 +16,20 @@ namespace Discord
private EmbedThumbnail? _thumbnail;
private List _fields;
- ///
- /// Returns the maximum number of fields allowed by Discord.
+ ///
+ /// Returns the maximum number of fields allowed by Discord.
///
public const int MaxFieldCount = 25;
- ///
- /// Returns the maximum length of title allowed by Discord.
+ ///
+ /// Returns the maximum length of title allowed by Discord.
///
public const int MaxTitleLength = 256;
- ///
- /// Returns the maximum length of description allowed by Discord.
+ ///
+ /// Returns the maximum length of description allowed by Discord.
///
public const int MaxDescriptionLength = 4096;
- ///
- /// Returns the maximum length of total characters allowed by Discord.
+ ///
+ /// Returns the maximum length of total characters allowed by Discord.
///
public const int MaxEmbedLength = 6000;
@@ -88,9 +88,9 @@ namespace Discord
}
/// Gets or sets the list of of an .
- /// An embed builder's fields collection is set to
+ /// An embed builder's fields collection is set to
/// null.
- /// Description length exceeds .
+ /// Fields count exceeds .
///
/// The list of existing .
public List Fields
@@ -137,7 +137,7 @@ namespace Discord
/// Gets the total length of all embed properties.
///
///
- /// The combined length of , , ,
+ /// The combined length of , , ,
/// , , and .
///
public int Length
@@ -166,7 +166,7 @@ namespace Discord
Title = title;
return this;
}
- ///
+ ///
/// Sets the description of an .
///
/// The description to be set.
@@ -178,7 +178,7 @@ namespace Discord
Description = description;
return this;
}
- ///
+ ///
/// Sets the URL of an .
///
/// The URL to be set.
@@ -190,7 +190,7 @@ namespace Discord
Url = url;
return this;
}
- ///
+ ///
/// Sets the thumbnail URL of an .
///
/// The thumbnail URL to be set.