Class Component<S extends Component<S,T,B,D>, T extends ActionComponent, B, D extends ComponentDefinition<T>>
- Type Parameters:
S- the concrete subtype ofComponentT- the type ofActionComponenttheComponentDefinitionrepresentsB- the type of builder theActionComponentusesD- the type ofComponentDefinitionthisComponentrepresents
- All Implemented Interfaces:
ActionRowChildComponent, ActionRowChildComponentUnion, Component, IComponentUnion, SectionAccessoryComponent, SectionAccessoryComponentUnion
- Direct Known Subclasses:
ButtonComponent, SelectMenuComponent, UnspecificComponent
Represents a component, namely Button, StringMenu or EntityMenu, that should be added to a reply.
Also holds the following two settings:
enabled:
to enable or disable the component
independent:
whether the component should be executed in the same Runtime as the command it is bound to or not. If true,
every component interaction will create a new Runtime. Furthermore, the component cannot expire and will always
get executed, even after a bot restart.
Example:
@SlashCommand("example command")
public void onCommand(CommandEvent event) {
event.with().components(Components.of(true, false, "onButton")).reply();
}
Component type specific implementations
If using one of:
button(Class, String, Entry...)entitySelect(Class, String, Entry...)stringSelect(Class, String, Entry...)
a specific implementation is returned which allows for further modification.
Example without localization
This example overrides the buttons label with "Modified Label"
@Command("example command")
public void onCommand(CommandEvent event) {
event.with().components(Components.button("onButton")
.label("Modified Label"))
.reply();
}
Example with localization
@Bundle("example")
@Command("example command")
public void onCommand(CommandEvent event, User user) {
event.with().components(Components.button("onButton")
.label("label", I18n.entry("name", user.getName())))
.reply();
}
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface Component
Component.Type -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasButton()protected abstract Dstatic ButtonComponentAdds aButtonComponentto the reply.static ButtonComponentAdds aButtonComponentto the reply.callback()static Component<?, ?, ?, ?> Adds a disabledComponentto the reply that is defined in a different class.static Component<?, ?, ?, ?> Adds disabled, runtime-boundComponents to the reply.protected booleanenabled()enabled(boolean enabled) static Component<?, ?, ?, ?> Adds an enabledComponentto the reply that is defined in a different class.static Component<?, ?, ?, ?> Adds an enabled, runtime-boundComponentto the reply.static EntitySelectMenuComponententitySelect(@Nullable Class<?> origin, String component, Entry... placeholder) Adds anEntitySelectMenuComponentto the reply.static EntitySelectMenuComponententitySelect(String component, Entry... placeholder) Adds anEntitySelectMenuComponentto the reply.intprotected booleanindependent(boolean independent) static Component<?, ?, ?, ?> independent(String component, Entry... placeholder) Adds an enabled, runtime-independentComponentto the reply.protected Stringname()static Component<?, ?, ?, ?> Adds aComponentwith the passed configuration to the reply.static Component<?, ?, ?, ?> Adds aComponentwith the passed configuration to the reply.static Component<?, ?, ?, ?> Adds aComponentwith the passed configuration to the reply.origin()protected Entry[]static ActionRowCreates anActionRowfrom the passed components.protected Sself()static StringSelectComponentstringSelect(@Nullable Class<?> origin, String component, Entry... placeholder) Adds aStringSelectComponentto the reply.static StringSelectComponentstringSelect(String component, Entry... placeholder) Adds aStringSelectComponentto the reply.withUniqueId(int uniqueId) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Component
getType, isMessageCompatible, isModalCompatibleMethods inherited from interface IComponentUnion
isUnknownComponent
-
Field Details
-
uniqueId
-
-
Constructor Details
-
Component
-
-
Method Details
-
enabled
Adds an enabled, runtime-boundComponentto the reply.- Parameters:
component- the name of the method that represents the componentplaceholder- the placeholders to use to perform message resolution
-
disabled
Adds disabled, runtime-boundComponents to the reply.- Parameters:
component- the name of the method that represents the componentplaceholder- the placeholders to use to perform message resolution
-
independent
Adds an enabled, runtime-independent
Componentto the reply.Every component interaction will create a new
Runtime. Furthermore, the component cannot expire and will always get executed, even after a bot restart.- Parameters:
component- the name of the method that represents the componentplaceholder- the placeholders to use to perform message resolution
-
enabled
Adds an enabledComponentto the reply that is defined in a different class. ThisComponentwill always be runtime-independent.- Parameters:
origin- theClassthecomponentis defined incomponent- the name of the method that represents the componentplaceholder- the placeholders to use to perform message resolution
-
disabled
Adds a disabledComponentto the reply that is defined in a different class. ThisComponentwill always be runtime-independent.- Parameters:
origin- theClassthecomponentis defined incomponent- the name of the method that represents the componentplaceholder- the placeholders to use to perform message resolution
-
of
public static Component<?,?, of?, ?> (boolean enabled, boolean independent, String component, Entry... placeholder) Adds aComponentwith the passed configuration to the reply.- Parameters:
enabled- whether theComponentshould be enabled or disabledindependent- whether theComponentshould be runtime-bound or independentcomponent- the name of the method that represents the componentplaceholder- the placeholders to use to perform message resolution
-
of
public static Component<?,?, of?, ?> (boolean enabled, Class<?> origin, String component, Entry... placeholder) Adds aComponentwith the passed configuration to the reply.- Parameters:
enabled- whether theComponentshould be enabled or disabledorigin- theClassthecomponentis defined incomponent- the name of the method that represents the componentplaceholder- the placeholders to use to perform message resolution
-
of
public static Component<?,?, of?, ?> (boolean enabled, boolean independent, Class<?> origin, String component, Entry... placeholder) Adds aComponentwith the passed configuration to the reply.- Parameters:
enabled- whether theComponentshould be enabled or disabledindependent- whether theComponentshould be runtime-bound or independentorigin- theClassthecomponentis defined incomponent- the name of the method that represents the componentplaceholder- the placeholders to use to perform message resolution
-
button
Adds aButtonComponentto the reply.- Parameters:
component- the name of the method that represents the buttonplaceholder- the placeholders to use to perform message resolution
-
button
public static ButtonComponent button(@Nullable Class<?> origin, String component, Entry... placeholder) Adds aButtonComponentto the reply.- Parameters:
origin- theClassthecomponentis defined incomponent- the name of the method that represents the buttonplaceholder- the placeholders to use to perform message resolution
-
entitySelect
Adds anEntitySelectMenuComponentto the reply.- Parameters:
component- the name of the method that represents the entity select menuplaceholder- the placeholders to use to perform message resolution
-
entitySelect
public static EntitySelectMenuComponent entitySelect(@Nullable Class<?> origin, String component, Entry... placeholder) Adds anEntitySelectMenuComponentto the reply.- Parameters:
origin- theClassthemenuis defined incomponent- the name of the method that represents the entity select menuplaceholder- the placeholders to use to perform message resolution
-
stringSelect
Adds aStringSelectComponentto the reply.- Parameters:
component- the name of the method that represents the string select menuplaceholder- the placeholders to use to perform message resolution
-
stringSelect
public static StringSelectComponent stringSelect(@Nullable Class<?> origin, String component, Entry... placeholder) Adds aStringSelectComponentto the reply.- Parameters:
origin- theClassthecomponentis defined incomponent- the name of the method that represents the string select menuplaceholder- the placeholders to use to perform message resolution
-
row
Creates an
ActionRowfrom the passed components.As with other methods of the class, the components are referenced by passing the name of the method(s) that represent the action component(s). The components will always be enabled and runtime-bound.
This is equivalent to:
ActionRow.of(Component.button("myButton"), Component.button("anotherButton"));- Parameters:
components- the name of the methods that represent the action components- Returns:
- an
ActionRowcontaining the provided components
-
enabled
- Parameters:
enabled- whether the component should be enabled- See Also:
-
independent
-
modify
- Parameters:
callback- aFunctionthat allows to modify the resulting jda object. The passed function will be called after all modifications except localization are made by jda-commands, shortly before the component is localized and then registered in the message
-
getUniqueId
public int getUniqueId()- Specified by:
getUniqueIdin interfaceComponent
-
withUniqueId
- Specified by:
withUniqueIdin interfaceActionRowChildComponent- Specified by:
withUniqueIdin interfaceActionRowChildComponentUnion- Specified by:
withUniqueIdin interfaceComponent- Specified by:
withUniqueIdin interfaceIComponentUnion- Specified by:
withUniqueIdin interfaceSectionAccessoryComponent- Specified by:
withUniqueIdin interfaceSectionAccessoryComponentUnion
-
asButton
- Specified by:
asButtonin interfaceActionRowChildComponentUnion- Specified by:
asButtonin interfaceSectionAccessoryComponentUnion
-
asStringSelectMenu
- Specified by:
asStringSelectMenuin interfaceActionRowChildComponentUnion
-
asEntitySelectMenu
- Specified by:
asEntitySelectMenuin interfaceActionRowChildComponentUnion
-
asThumbnail
- Specified by:
asThumbnailin interfaceSectionAccessoryComponentUnion
-
enabled
protected boolean enabled() -
independent
protected boolean independent() -
name
-
origin
-
callback
-
placeholder
-
self
-
definitionClass
-
build
-