Table of Contents

Class ComponentBuilder

Namespace
Discord
Assembly
Discord.Net.Core.dll

Represents a builder for creating a MessageComponent.

public class ComponentBuilder
Inheritance
ComponentBuilder
Inherited Members

Fields

MaxActionRowCount

The max amount of rows a message can have.

public const int MaxActionRowCount = 5

Field Value

int

MaxCustomIdLength

The max length of a CustomId.

public const int MaxCustomIdLength = 100

Field Value

int

Properties

ActionRows

Gets or sets the Action Rows for this Component Builder.

public List<ActionRowBuilder> ActionRows { get; set; }

Property Value

List<ActionRowBuilder>

Exceptions

ArgumentNullException

ActionRows cannot be null.

ArgumentException

ActionRows count exceeds MaxActionRowCount.

Methods

AddRow(ActionRowBuilder)

Adds a row to this component builder.

public ComponentBuilder AddRow(ActionRowBuilder row)

Parameters

row ActionRowBuilder

The row to add.

Returns

ComponentBuilder

The current builder.

Exceptions

IndexOutOfRangeException

The component builder contains the max amount of rows defined as MaxActionRowCount.

Build()

Builds this builder into a MessageComponent used to send your components.

public MessageComponent Build()

Returns

MessageComponent

A MessageComponent that can be sent with SendMessageAsync(string, bool, Embed, RequestOptions, AllowedMentions, MessageReference, MessageComponent, ISticker[], Embed[], MessageFlags, PollProperties).

FromComponents(IReadOnlyCollection<IMessageComponent>)

Creates a new builder from the provided list of components.

public static ComponentBuilder FromComponents(IReadOnlyCollection<IMessageComponent> components)

Parameters

components IReadOnlyCollection<IMessageComponent>

The components to create the builder from.

Returns

ComponentBuilder

The newly created builder.

FromMessage(IMessage)

Creates a new builder from a message.

public static ComponentBuilder FromMessage(IMessage message)

Parameters

message IMessage

The message to create the builder from.

Returns

ComponentBuilder

The newly created builder.

RemoveButtonByURL(string)

Removes a Link Button from the ComponentBuilder based on its URL.

public ComponentBuilder RemoveButtonByURL(string url)

Parameters

url string

The URL of the Link Button.

Returns

ComponentBuilder

The current builder.

RemoveComponent(string)

Removes a component from the ComponentBuilder.

public ComponentBuilder RemoveComponent(string customId)

Parameters

customId string

The custom id of the component.

Returns

ComponentBuilder

The current builder.

RemoveComponentsOfType(ComponentType)

Removes all components of the given type from the ComponentBuilder.

public ComponentBuilder RemoveComponentsOfType(ComponentType t)

Parameters

t ComponentType

The ComponentType to remove.

Returns

ComponentBuilder

The current builder.

WithButton(ButtonBuilder, int)

Adds a ButtonBuilder to the ComponentBuilder at the specific row. If the row cannot accept the component then it will add it to a row that can.

public ComponentBuilder WithButton(ButtonBuilder button, int row = 0)

Parameters

button ButtonBuilder

The button to add.

row int

The row to add the button.

Returns

ComponentBuilder

The current builder.

Exceptions

InvalidOperationException

There is no more row to add a button.

ArgumentException

row must be less than MaxActionRowCount.

WithButton(string, string, ButtonStyle, IEmote, string, bool, int, ulong?)

Adds a ButtonBuilder with specified parameters to the ComponentBuilder at the specific row. If the row cannot accept the component then it will add it to a row that can.

public ComponentBuilder WithButton(string label = null, string customId = null, ButtonStyle style = ButtonStyle.Primary, IEmote emote = null, string url = null, bool disabled = false, int row = 0, ulong? skuId = null)

Parameters

label string

The label text for the newly added button.

customId string

The custom id of the newly added button.

style ButtonStyle

The style of this newly added button.

emote IEmote

A IEmote to be used with this button.

url string

A URL to be used only if the ButtonStyle is a Link.

disabled bool

Whether or not the newly created button is disabled.

row int

The row the button should be placed on.

skuId ulong?

The id of the sku associated with the current button.

Returns

ComponentBuilder

The current builder.

WithRows(IEnumerable<ActionRowBuilder>)

Sets the rows of this component builder to a specified collection.

public ComponentBuilder WithRows(IEnumerable<ActionRowBuilder> rows)

Parameters

rows IEnumerable<ActionRowBuilder>

The rows to set.

Returns

ComponentBuilder

The current builder.

Exceptions

IndexOutOfRangeException

The collection contains more rows then is allowed by discord.

WithSelectMenu(SelectMenuBuilder, int)

Adds a SelectMenuBuilder to the ComponentBuilder at the specific row. If the row cannot accept the component then it will add it to a row that can.

public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row = 0)

Parameters

menu SelectMenuBuilder

The menu to add.

row int

The row to attempt to add this component on.

Returns

ComponentBuilder

The current builder.

Exceptions

InvalidOperationException

There is no more row to add a menu.

ArgumentException

row must be less than MaxActionRowCount.

WithSelectMenu(string, List<SelectMenuOptionBuilder>, string, int, int, bool, int, ComponentType, ChannelType[], SelectMenuDefaultValue[])

Adds a SelectMenuBuilder to the ComponentBuilder at the specific row. If the row cannot accept the component then it will add it to a row that can.

public ComponentBuilder WithSelectMenu(string customId, List<SelectMenuOptionBuilder> options = null, string placeholder = null, int minValues = 1, int maxValues = 1, bool disabled = false, int row = 0, ComponentType type = ComponentType.SelectMenu, ChannelType[] channelTypes = null, SelectMenuDefaultValue[] defaultValues = null)

Parameters

customId string

The custom id of the menu.

options List<SelectMenuOptionBuilder>

The options of the menu.

placeholder string

The placeholder of the menu.

minValues int

The min values of the placeholder.

maxValues int

The max values of the placeholder.

disabled bool

Whether or not the menu is disabled.

row int

The row to add the menu to.

type ComponentType

The type of the select menu.

channelTypes ChannelType[]

Menus valid channel types (only for ChannelSelect)

defaultValues SelectMenuDefaultValue[]

Returns

ComponentBuilder