/// Represents a <see cref="IMessageComponent"/> Button.
/// </summary>
public class ButtonComponent : IMessageComponent
{
/// <inheritdoc/>
public ComponentType Type { get; } = ComponentType.Button;
/// <summary>
/// The <see cref="ButtonStyle"/> of this button, example buttons with each style can be found <see href="https://discord.com/assets/7bb017ce52cfd6575e21c058feb3883b.png">Here</see>.
/// </summary>
public ButtonStyle Style { get; }
/// <summary>
/// The label of the button, this is the text that is shown.
/// </summary>
public string Label { get; }
/// <summary>
/// A <see cref="IEmote"/> that will be displayed with this button.
/// </summary>
public IEmote Emote { get; }
/// <summary>
/// A unique id that will be sent with a <see cref="IDiscordInteraction"/>. This is how you know what button was pressed.
/// </summary>
public string CustomId { get; }
/// <summary>
/// A URL for a <see cref="ButtonStyle.Link"/> button.
/// </summary>
/// <remarks>
/// You cannot have a button with a <b>URL</b> and a <b>CustomId</b>.
/// <param name="label">The label text for the newly added button.</param>
/// <param name="style">The style of this newly added button.</param>
/// <param name="emote">A <see cref="IEmote"/> to be used with this button.</param>
/// <param name="customId">The custom id of the newly added button.</param>
/// <param name="url">A URL to be used only if the <see cref="ButtonStyle"/> is a Link.</param>
/// <param name="disabled">Whether or not the newly created button is disabled.</param>
/// <param name="row">The row the button should be placed on.</param>
/// <returns>The current builder.</returns>
public ComponentBuilder WithButton(
string label,
string customId,
ButtonStyle style = ButtonStyle.Primary,
IEmote emote = null,
string customId = null,
string url = null,
bool disabled = false,
int row = 0)
@@ -45,9 +65,20 @@ namespace Discord
return this.WithButton(button, row);
}
/// <summary>
/// Adds a button to the first row.
/// </summary>
/// <param name="button">The button to add to the first row.</param>
/// <returns>The current builder.</returns>
public ComponentBuilder WithButton(ButtonBuilder button)
=> this.WithButton(button, 0);
/// <summary>
/// Adds a button to the specified row.
/// </summary>
/// <param name="button">The button to add.</param>
/// <param name="row">The row to add the button.</param>
/// <returns>The current builder.</returns>
public ComponentBuilder WithButton(ButtonBuilder button, int row)
{
var builtButton = button.Build();
@@ -75,6 +106,10 @@ namespace Discord
return this;
}
/// <summary>
/// Builds this builder into a <see cref="MessageComponent"/> used to send your components.
/// </summary>
/// <returns>A <see cref="MessageComponent"/> that can be sent with <see cref="IMessageChannel.SendMessageAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent)"/></returns>
public MessageComponent Build()
{
if (this._actionRows != null)
@@ -84,9 +119,19 @@ namespace Discord
}
}
/// <summary>
/// Represents a class used to build Action rows.
/// </summary>
public class ActionRowBuilder
{
/// <summary>
/// The max amount of child components this row can hold.
/// Represents a Websocket-based interaction type for Message Components.
/// </summary>
public class SocketMessageComponent : SocketInteraction
{
/// <summary>
/// The data received with this interaction, contains the button that was clicked.
/// </summary>
new public SocketMessageComponentData Data { get; }
/// <summary>
/// The message that contained the trigger for this interaction.
/// </summary>
public SocketMessage Message { get; private set; }
internal SocketMessageComponent(DiscordSocketClient client, Model model)
@@ -72,7 +81,6 @@ namespace Discord.WebSocket
/// </returns>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
/// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception>
public override async Task<RestUserMessage> RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,