Class Component<S extends Component<S,T,B,D>, T extends net.dv8tion.jda.api.components.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:
net.dv8tion.jda.api.components.actionrow.ActionRowChildComponent, net.dv8tion.jda.api.components.actionrow.ActionRowChildComponentUnion, net.dv8tion.jda.api.components.Component, net.dv8tion.jda.api.components.IComponentUnion, net.dv8tion.jda.api.components.section.SectionAccessoryComponent, net.dv8tion.jda.api.components.section.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 net.dv8tion.jda.api.components.Component
net.dv8tion.jda.api.components.Component.Type -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionnet.dv8tion.jda.api.components.buttons.ButtonasButton()net.dv8tion.jda.api.components.selections.EntitySelectMenunet.dv8tion.jda.api.components.selections.StringSelectMenunet.dv8tion.jda.api.components.thumbnail.Thumbnailprotected 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[]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 net.dv8tion.jda.api.components.Component
getType, isMessageCompatible, isModalCompatibleMethods inherited from interface net.dv8tion.jda.api.components.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
-
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 interfacenet.dv8tion.jda.api.components.Component
-
withUniqueId
- Specified by:
withUniqueIdin interfacenet.dv8tion.jda.api.components.actionrow.ActionRowChildComponent- Specified by:
withUniqueIdin interfacenet.dv8tion.jda.api.components.actionrow.ActionRowChildComponentUnion- Specified by:
withUniqueIdin interfacenet.dv8tion.jda.api.components.Component- Specified by:
withUniqueIdin interfacenet.dv8tion.jda.api.components.IComponentUnion- Specified by:
withUniqueIdin interfacenet.dv8tion.jda.api.components.section.SectionAccessoryComponent- Specified by:
withUniqueIdin interfacenet.dv8tion.jda.api.components.section.SectionAccessoryComponentUnion
-
asButton
public net.dv8tion.jda.api.components.buttons.Button asButton()- Specified by:
asButtonin interfacenet.dv8tion.jda.api.components.actionrow.ActionRowChildComponentUnion- Specified by:
asButtonin interfacenet.dv8tion.jda.api.components.section.SectionAccessoryComponentUnion
-
asStringSelectMenu
public net.dv8tion.jda.api.components.selections.StringSelectMenu asStringSelectMenu()- Specified by:
asStringSelectMenuin interfacenet.dv8tion.jda.api.components.actionrow.ActionRowChildComponentUnion
-
asEntitySelectMenu
public net.dv8tion.jda.api.components.selections.EntitySelectMenu asEntitySelectMenu()- Specified by:
asEntitySelectMenuin interfacenet.dv8tion.jda.api.components.actionrow.ActionRowChildComponentUnion
-
asThumbnail
public net.dv8tion.jda.api.components.thumbnail.Thumbnail asThumbnail()- Specified by:
asThumbnailin interfacenet.dv8tion.jda.api.components.section.SectionAccessoryComponentUnion
-
enabled
protected boolean enabled() -
independent
protected boolean independent() -
name
-
origin
-
callback
-
placeholder
-
self
-
definitionClass
-
build
-