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 the [ActionComponent uses]D- the type ofComponentDefinitionthisComponentrepresents
- Direct Known Subclasses:
ButtonComponent, SelectMenuComponent, UnspecificComponent
Represents a component, namely Button, StringSelectMenu or EntitySelectMenu, 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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.protected 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.
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
of
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
button
Adds aButtonComponentto the reply.- Parameters:
component- the name of the method that represents the buttonplaceholder- the placeholders to use to perform localization, see [I18n#localize(Locale, String, Entry...) ]
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
entitySelect
Adds anEntitySelectMenuComponentto the reply.- Parameters:
component- the name of the method that represents the entity select menuplaceholder- the placeholders to use to perform localization, see [I18n#localize(Locale, String, Entry...) ]
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
stringSelect
Adds aStringSelectComponentto the reply.- Parameters:
component- the name of the method that represents the string select menuplaceholder- the placeholders to use to perform localization, see [I18n#localize(Locale, String, Entry...) ]
-
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 localization, see [I18n#localize(Locale, String, Entry...) ]
-
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
-
enabled
protected boolean enabled() -
independent
protected boolean independent() -
name
-
origin
-
callback
-
placeholder
-
self
-
definitionClass
-
build
-