Add AddRow and WithRows to ComponentBuilder (#2038)

This commit is contained in:
Quin Lynch
2022-01-14 07:55:36 -04:00
committed by GitHub
parent c1641f12fc
commit 3429cf99c8

View File

@@ -238,6 +238,38 @@ namespace Discord
return this;
}
/// <summary>
/// Adds a row to this component builder.
/// </summary>
/// <param name="row">The row to add.</param>
/// <exception cref="IndexOutOfRangeException">The component builder contains the max amount of rows defined as <see cref="MaxActionRowCount"/>.</exception>
/// <returns>The current builder.</returns>
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;
}
/// <summary>
/// Sets the rows of this component builder to a specified collection.
/// </summary>
/// <param name="rows">The rows to set.</param>
/// <exception cref="IndexOutOfRangeException">The collection contains more rows then is allowed by discord.</exception>
/// <returns>The current builder.</returns>
public ComponentBuilder WithRows(IEnumerable<ActionRowBuilder> rows)
{
if (rows.Count() > MaxActionRowCount)
throw new IndexOutOfRangeException($"Cannot have more than {MaxActionRowCount} rows");
_actionRows = new List<ActionRowBuilder>(rows);
return this;
}
/// <summary>
/// Builds this builder into a <see cref="MessageComponent"/> used to send your components.
/// </summary>