From 3429cf99c8b64e19973882d7ecb9bb7f2f13ffca Mon Sep 17 00:00:00 2001
From: Quin Lynch <49576606+quinchs@users.noreply.github.com>
Date: Fri, 14 Jan 2022 07:55:36 -0400
Subject: [PATCH] Add AddRow and WithRows to ComponentBuilder (#2038)
---
.../MessageComponents/ComponentBuilder.cs | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs
index 4461a4205..b086535f7 100644
--- a/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs
@@ -238,6 +238,38 @@ namespace Discord
return this;
}
+ ///
+ /// Adds a row to this component builder.
+ ///
+ /// The row to add.
+ /// The component builder contains the max amount of rows defined as .
+ /// The current builder.
+ public ComponentBuilder AddRow(ActionRowBuilder row)
+ {
+ _actionRows ??= new();
+
+ if (_actionRows.Count >= MaxActionRowCount)
+ throw new IndexOutOfRangeException("The max amount of rows has been reached");
+
+ ActionRows.Add(row);
+ return this;
+ }
+
+ ///
+ /// Sets the rows of this component builder to a specified collection.
+ ///
+ /// The rows to set.
+ /// The collection contains more rows then is allowed by discord.
+ /// The current builder.
+ public ComponentBuilder WithRows(IEnumerable rows)
+ {
+ if (rows.Count() > MaxActionRowCount)
+ throw new IndexOutOfRangeException($"Cannot have more than {MaxActionRowCount} rows");
+
+ _actionRows = new List(rows);
+ return this;
+ }
+
///
/// Builds this builder into a used to send your components.
///