Browse Source

Add AddRow and WithRows to ComponentBuilder (#2038)

tags/3.2.0
Quin Lynch GitHub 3 years ago
parent
commit
3429cf99c8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions
  1. +32
    -0
      src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs

+ 32
- 0
src/Discord.Net.Core/Entities/Interactions/MessageComponents/ComponentBuilder.cs 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>


Loading…
Cancel
Save