Class ButtonBuilder
- Namespace
- Discord
- Assembly
- Discord.Net.Core.dll
Represents a class used to build ButtonComponent's.
public class ButtonBuilder : IInteractableComponentBuilder, IMessageComponentBuilder
- Inheritance
-
ButtonBuilder
- Implements
- Inherited Members
- Extension Methods
Constructors
ButtonBuilder()
Creates a new instance of a ButtonBuilder.
public ButtonBuilder()
ButtonBuilder(ButtonComponent)
Creates a new instance of a ButtonBuilder from instance of a ButtonComponent.
public ButtonBuilder(ButtonComponent button)
Parameters
buttonButtonComponent
ButtonBuilder(string, string, ButtonStyle, string, IEmote, bool, ulong?, int?)
Creates a new instance of a ButtonBuilder.
public ButtonBuilder(string label = null, string customId = null, ButtonStyle style = ButtonStyle.Primary, string url = null, IEmote emote = null, bool isDisabled = false, ulong? skuId = null, int? id = null)
Parameters
labelstringThe label to use on the newly created link button.
customIdstringThe custom ID of this button.
styleButtonStyleThe custom ID of this button.
urlstringThe url of this button.
emoteIEmoteThe emote of this button.
isDisabledboolDisabled this button or not.
skuIdulong?The sku id of this button.
idint?
Fields
MaxButtonLabelLength
The max length of a Label.
public const int MaxButtonLabelLength = 80
Field Value
Properties
CustomId
Gets or sets the custom id of the current button.
public string CustomId { get; set; }
Property Value
Exceptions
- ArgumentException
CustomId length exceeds MaxCustomIdLength
- ArgumentException
CustomId length subceeds 1.
Emote
Gets or sets the IEmote of the current button.
public IEmote Emote { get; set; }
Property Value
Id
Gets or sets the id for the component. An autoincremented id will be assigned if not set.
public int? Id { get; set; }
Property Value
- int?
IsDisabled
Gets or sets whether the current button is disabled.
public bool IsDisabled { get; set; }
Property Value
Label
Gets or sets the label of the current button.
public string Label { get; set; }
Property Value
Exceptions
- ArgumentException
Label length exceeds MaxButtonLabelLength.
- ArgumentException
Label length exceeds MaxButtonLabelLength.
SkuId
Gets or sets the id of the sku associated with the current button.
public ulong? SkuId { get; set; }
Property Value
Remarks
Style
Gets or sets the ButtonStyle of the current button.
public ButtonStyle Style { get; set; }
Property Value
Type
Gets the type of the component.
public ComponentType Type { get; }
Property Value
Url
Gets or sets the url of the current button.
public string Url { get; set; }
Property Value
Methods
Build()
Builds this builder into a ButtonComponent to be used in a ComponentBuilder.
public ButtonComponent Build()
Returns
- ButtonComponent
A ButtonComponent to be used in a ComponentBuilder.
Exceptions
- InvalidOperationException
A button must contain either a Url or a CustomId, but not both.
- InvalidOperationException
- InvalidOperationException
A link button must contain a URL.
- InvalidOperationException
A URL must include a protocol (http or https).
- InvalidOperationException
A non-link button must contain a custom id
CreateDangerButton(string, string, IEmote)
Creates a button with the Danger style.
public static ButtonBuilder CreateDangerButton(string label, string customId, IEmote emote = null)
Parameters
labelstringThe label for this danger button.
customIdstringThe custom id for this danger button.
emoteIEmoteThe emote for this danger button.
Returns
- ButtonBuilder
A builder with the newly created button.
CreateLinkButton(string, string, IEmote)
Creates a button with the Link style.
public static ButtonBuilder CreateLinkButton(string label, string url, IEmote emote = null)
Parameters
labelstringThe label for this link button.
urlstringThe url for this link button to go to.
emoteIEmoteThe emote for this link button.
Returns
- ButtonBuilder
A builder with the newly created button.
CreatePremiumButton(string, ulong, IEmote)
Creates a button with the Premium style.
public static ButtonBuilder CreatePremiumButton(string label, ulong skuId, IEmote emote = null)
Parameters
labelstringThe label for this premium button.
skuIdulongThe sku id for this premium button.
emoteIEmoteThe emote for this premium button.
Returns
- ButtonBuilder
A builder with the newly created button.
CreatePrimaryButton(string, string, IEmote)
Creates a button with the Primary style.
public static ButtonBuilder CreatePrimaryButton(string label, string customId, IEmote emote = null)
Parameters
labelstringThe label for this primary button.
customIdstringThe custom id for this primary button.
emoteIEmoteThe emote for this primary button.
Returns
- ButtonBuilder
A builder with the newly created button.
CreateSecondaryButton(string, string, IEmote)
Creates a button with the Secondary style.
public static ButtonBuilder CreateSecondaryButton(string label, string customId, IEmote emote = null)
Parameters
labelstringThe label for this secondary button.
customIdstringThe custom id for this secondary button.
emoteIEmoteThe emote for this secondary button.
Returns
- ButtonBuilder
A builder with the newly created button.
CreateSuccessButton(string, string, IEmote)
Creates a button with the Success style.
public static ButtonBuilder CreateSuccessButton(string label, string customId, IEmote emote = null)
Parameters
labelstringThe label for this success button.
customIdstringThe custom id for this success button.
emoteIEmoteThe emote for this success button.
Returns
- ButtonBuilder
A builder with the newly created button.
WithCustomId(string)
Sets the custom id of the current button.
public ButtonBuilder WithCustomId(string id)
Parameters
idstringThe id to use for the current button.
Returns
- ButtonBuilder
The current builder.
Exceptions
- ArgumentException
CustomId length exceeds MaxCustomIdLength
- ArgumentException
CustomId length subceeds 1.
WithDisabled(bool)
Sets whether the current button is disabled.
public ButtonBuilder WithDisabled(bool isDisabled)
Parameters
isDisabledboolWhether the current button is disabled or not.
Returns
- ButtonBuilder
The current builder.
WithEmote(IEmote)
Sets the current buttons emote.
public ButtonBuilder WithEmote(IEmote emote)
Parameters
emoteIEmoteThe emote to use for the current button.
Returns
- ButtonBuilder
The current builder.
WithLabel(string)
Sets the current buttons label to the specified text.
public ButtonBuilder WithLabel(string label)
Parameters
labelstringThe text for the label.
Returns
- ButtonBuilder
The current builder.
Exceptions
- ArgumentException
Label length exceeds MaxButtonLabelLength.
- ArgumentException
Label length exceeds MaxButtonLabelLength.
WithSkuId(ulong?)
Sets the sku id of the current button.
public ButtonBuilder WithSkuId(ulong? skuId)
Parameters
skuIdulong?The id of the sku
Returns
- ButtonBuilder
The current builder.
WithStyle(ButtonStyle)
Sets the current buttons style.
public ButtonBuilder WithStyle(ButtonStyle style)
Parameters
styleButtonStyleThe style for this builders button.
Returns
- ButtonBuilder
The current builder.
WithUrl(string)
Sets the current buttons url.
public ButtonBuilder WithUrl(string url)
Parameters
urlstringThe url to use for the current button.
Returns
- ButtonBuilder
The current builder.