Table of Contents

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 string

The label to use on the newly created link button.

customId string

The custom ID of this button.

style ButtonStyle

The custom ID of this button.

url string

The url of this button.

emote IEmote

The emote of this button.

isDisabled bool

Disabled 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

int

Properties

CustomId

Gets or sets the custom id of the current button.

public string CustomId { get; set; }

Property Value

string

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

IEmote

IsDisabled

Gets or sets whether the current button is disabled.

public bool IsDisabled { get; set; }

Property Value

bool

Label

Gets or sets the label of the current button.

public string Label { get; set; }

Property Value

string

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

ulong?

Remarks

null if the button is not of type Premium.

Style

Gets or sets the ButtonStyle of the current button.

public ButtonStyle Style { get; set; }

Property Value

ButtonStyle

Url

Gets or sets the url of the current button.

public string Url { get; set; }

Property Value

string

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

A button must have an Emote or a Label.

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 string

The label for this danger button.

customId string

The custom id for this danger button.

emote IEmote

The 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 string

The label for this link button.

url string

The url for this link button to go to.

emote IEmote

The 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 string

The label for this premium button.

skuId ulong

The sku id for this premium button.

emote IEmote

The 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 string

The label for this primary button.

customId string

The custom id for this primary button.

emote IEmote

The 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 string

The label for this secondary button.

customId string

The custom id for this secondary button.

emote IEmote

The 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 string

The label for this success button.

customId string

The custom id for this success button.

emote IEmote

The 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 string

The 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 bool

Whether 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 IEmote

The 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 string

The 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 ButtonStyle

The style for this builders button.

Returns

ButtonBuilder

The current builder.

WithUrl(string)

Sets the current buttons url.

public ButtonBuilder WithUrl(string url)

Parameters

url string

The url to use for the current button.

Returns

ButtonBuilder

The current builder.