/// Represents a <see cref="IMessageComponent"/> Button.
/// </summary>
public class ButtonComponent : IMessageComponent
public class ButtonComponent : IMessageComponent
{
{
[JsonProperty("type")]
/// <inheritdoc/>
public ComponentType Type { get; } = ComponentType.Button;
public ComponentType Type { get; } = ComponentType.Button;
[JsonProperty("style")]
/// <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; }
public ButtonStyle Style { get; }
[JsonProperty("label")]
/// <summary>
/// The label of the button, this is the text that is shown.
/// </summary>
public string Label { get; }
public string Label { get; }
[JsonProperty("emoji")]
/// <summary>
/// A <see cref="IEmote"/> that will be displayed with this button.
/// </summary>
public IEmote Emote { get; }
public IEmote Emote { get; }
[JsonProperty("custom_id")]
/// <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; }
public string CustomId { get; }
[JsonProperty("url")]
/// <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(
public ComponentBuilder WithButton(
string label,
string label,
string customId,
ButtonStyle style = ButtonStyle.Primary,
ButtonStyle style = ButtonStyle.Primary,
IEmote emote = null,
IEmote emote = null,
string customId = null,
string url = null,
string url = null,
bool disabled = false,
bool disabled = false,
int row = 0)
int row = 0)
@@ -45,9 +65,20 @@ namespace Discord
return this.WithButton(button, row);
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)
public ComponentBuilder WithButton(ButtonBuilder button)
=> this.WithButton(button, 0);
=> 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)
public ComponentBuilder WithButton(ButtonBuilder button, int row)
{
{
var builtButton = button.Build();
var builtButton = button.Build();
@@ -75,6 +106,10 @@ namespace Discord
return this;
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()
public MessageComponent Build()
{
{
if (this._actionRows != null)
if (this._actionRows != null)
@@ -84,10 +119,20 @@ namespace Discord
}
}
}
}
/// <summary>
/// Represents a class used to build Action rows.
/// </summary>
public class ActionRowBuilder
public class ActionRowBuilder
{
{
/// <summary>
/// The max amount of child components this row can hold.
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
/// <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>
/// <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,
public override async Task<RestUserMessage> RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.