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
MaxCustomIdLength
The max length of a CustomId.
public const int MaxCustomIdLength = 100
Field Value
Properties
ActionRows
Gets or sets the Action Rows for this Component Builder.
public List<ActionRowBuilder> ActionRows { get; set; }
Property Value
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
rowActionRowBuilderThe 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
componentsIReadOnlyCollection<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
messageIMessageThe 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
urlstringThe URL of the Link Button.
Returns
- ComponentBuilder
The current builder.
RemoveComponent(string)
Removes a component from the ComponentBuilder.
public ComponentBuilder RemoveComponent(string customId)
Parameters
customIdstringThe 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
tComponentTypeThe 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
buttonButtonBuilderThe button to add.
rowintThe row to add the button.
Returns
- ComponentBuilder
The current builder.
Exceptions
- InvalidOperationException
There is no more row to add a button.
- ArgumentException
rowmust 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
labelstringThe label text for the newly added button.
customIdstringThe custom id of the newly added button.
styleButtonStyleThe style of this newly added button.
emoteIEmoteA IEmote to be used with this button.
urlstringA URL to be used only if the ButtonStyle is a Link.
disabledboolWhether or not the newly created button is disabled.
rowintThe row the button should be placed on.
skuIdulong?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
rowsIEnumerable<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
menuSelectMenuBuilderThe menu to add.
rowintThe 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
rowmust 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
customIdstringThe custom id of the menu.
optionsList<SelectMenuOptionBuilder>The options of the menu.
placeholderstringThe placeholder of the menu.
minValuesintThe min values of the placeholder.
maxValuesintThe max values of the placeholder.
disabledboolWhether or not the menu is disabled.
rowintThe row to add the menu to.
typeComponentTypeThe type of the select menu.
channelTypesChannelType[]Menus valid channel types (only for ChannelSelect)
defaultValuesSelectMenuDefaultValue[]