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
row
ActionRowBuilderThe 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
IMessageThe 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
stringThe 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
stringThe 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
ComponentTypeThe 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
ButtonBuilderThe button to add.
row
intThe 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
stringThe label text for the newly added button.
customId
stringThe custom id of the newly added button.
style
ButtonStyleThe style of this newly added button.
emote
IEmoteA IEmote to be used with this button.
url
stringA URL to be used only if the ButtonStyle is a Link.
disabled
boolWhether or not the newly created button is disabled.
row
intThe 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
SelectMenuBuilderThe menu to add.
row
intThe 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
stringThe custom id of the menu.
options
List<SelectMenuOptionBuilder>The options of the menu.
placeholder
stringThe placeholder of the menu.
minValues
intThe min values of the placeholder.
maxValues
intThe max values of the placeholder.
disabled
boolWhether or not the menu is disabled.
row
intThe row to add the menu to.
type
ComponentTypeThe type of the select menu.
channelTypes
ChannelType[]Menus valid channel types (only for ChannelSelect)
defaultValues
SelectMenuDefaultValue[]