Class ButtonBuilder
- Namespace
- Discord
- Assembly
- Discord.Net.Core.dll
Represents a class used to build ButtonComponent's.
public class ButtonBuilder
- Inheritance
-
ButtonBuilder
- Inherited Members
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
button
ButtonComponent
ButtonBuilder(string, string, ButtonStyle, string, IEmote, bool, ulong?)
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)
Parameters
label
stringThe label to use on the newly created link button.
customId
stringThe custom ID of this button.
style
ButtonStyleThe custom ID of this button.
url
stringThe url of this button.
emote
IEmoteThe emote of this button.
isDisabled
boolDisabled this button or not.
skuId
ulong?The sku id of this button.
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
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
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
label
stringThe label for this danger button.
customId
stringThe custom id for this danger button.
emote
IEmoteThe 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
label
stringThe label for this link button.
url
stringThe url for this link button to go to.
emote
IEmoteThe 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
label
stringThe label for this premium button.
skuId
ulongThe sku id for this premium button.
emote
IEmoteThe 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
label
stringThe label for this primary button.
customId
stringThe custom id for this primary button.
emote
IEmoteThe 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
label
stringThe label for this secondary button.
customId
stringThe custom id for this secondary button.
emote
IEmoteThe 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
label
stringThe label for this success button.
customId
stringThe custom id for this success button.
emote
IEmoteThe 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
id
stringThe 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
isDisabled
boolWhether 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
emote
IEmoteThe 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
label
stringThe 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
skuId
ulong?The id of the sku
Returns
- ButtonBuilder
The current builder.
WithStyle(ButtonStyle)
Sets the current buttons style.
public ButtonBuilder WithStyle(ButtonStyle style)
Parameters
style
ButtonStyleThe style for this builders button.
Returns
- ButtonBuilder
The current builder.
WithUrl(string)
Sets the current buttons url.
public ButtonBuilder WithUrl(string url)
Parameters
url
stringThe url to use for the current button.
Returns
- ButtonBuilder
The current builder.