ComponentContainer

open class ComponentContainer(val timeout: Duration? = null, startTimeoutNow: Boolean = false) : KordExKoinComponent

Class representing a single set of components that can be applied to any message.

A timeout is supported by this class. If a timeout is provided, the components stored within this container will be unregistered from the ComponentRegistry. If this container contains actionable components, the timeout will be reset whenever an actionable component is interacted with.

The startTimeoutNow parameter defaults to false, but will be set to true automatically if you're using a components DSL function provided in the message creation/modification builders. When this is true, the timeout task will be started immediately - when it's false, you'll have to call the timeoutTask start function yourself.

Parameters

timeout

Optional timeout duration.

startTimeoutNow

Whether to start the timeout immediately.

Constructors

Link copied to clipboard
constructor(timeout: Duration? = null, startTimeoutNow: Boolean = false)

Properties

Link copied to clipboard

Array containing sorted rows of components.

Link copied to clipboard
val timeout: Duration? = null
Link copied to clipboard
open var timeoutCallback: suspend ComponentContainer.() -> Unit?

Extra callback to run when this container times out, if any.

Link copied to clipboard
open val timeoutTask: Task?

If a timeout was provided, the scheduled timeout task will be stored here.

Link copied to clipboard

Components that haven't been sorted into rows by sort yet.

Functions

Link copied to clipboard
open suspend fun add(component: Component, rowNum: Int? = null)

Add a component. New components will be unsorted, or placed in the numbered row denoted by rowNum if possible.

Link copied to clipboard
open suspend fun MessageBuilder.applyToMessage()

Apply the components in this container to a message that's being created or edited.

Link copied to clipboard
open suspend fun cancel()

Cancel the timeout task, and remove all components from this component container.

Link copied to clipboard

DSL function for creating a disabled button and adding it to the current ComponentContainer.

Link copied to clipboard

DSL function for creating an ephemeral button and adding it to the current ComponentContainer.

suspend fun <M : ModalForm> ComponentContainer.ephemeralButton(modal: () -> M?, row: Int? = null, builder: suspend EphemeralInteractionButton<M>.() -> Unit): EphemeralInteractionButton<M>

DSL function for creating an ephemeral button with modal, and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.ephemeralChannelSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend EphemeralChannelSelectMenu<M>.() -> Unit): EphemeralChannelSelectMenu<M>

DSL function for creating an ephemeral channel select menu and adding it to the current ComponentContainer.

Link copied to clipboard

DSL function for creating an ephemeral mentionable select menu, and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.ephemeralRoleSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend EphemeralRoleSelectMenu<M>.() -> Unit): EphemeralRoleSelectMenu<M>

DSL function for creating an ephemeral role select menu and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.ephemeralStringSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend EphemeralStringSelectMenu<M>.() -> Unit): EphemeralStringSelectMenu<M>

DSL function for creating an ephemeral string select menu and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.ephemeralUserSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend EphemeralUserSelectMenu<M>.() -> Unit): EphemeralUserSelectMenu<M>

DSL function for creating an ephemeral user select menu and adding it to the current ComponentContainer.

Link copied to clipboard
open override fun getKoin(): Koin

Get the associated Koin instance.

Link copied to clipboard
suspend fun ComponentContainer.linkButton(row: Int? = null, builder: suspend LinkInteractionButton.() -> Unit): LinkInteractionButton

DSL function for creating a link button and adding it to the current ComponentContainer.

Link copied to clipboard
open fun onTimeout(callback: suspend ComponentContainer.() -> Unit)

Register an additional callback to be run when this container times out, assuming a timeout is configured.

Link copied to clipboard

DSL function for creating a public button and adding it to the current ComponentContainer.

suspend fun <M : ModalForm> ComponentContainer.publicButton(modal: () -> M?, row: Int? = null, builder: suspend PublicInteractionButton<M>.() -> Unit): PublicInteractionButton<M>

DSL function for creating a public button with modal, and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.publicChannelSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend PublicChannelSelectMenu<M>.() -> Unit): PublicChannelSelectMenu<M>

DSL function for creating a public channel select menu and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.publicMentionableSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend PublicMentionableSelectMenu<M>.() -> Unit): PublicMentionableSelectMenu<M>

DSL function for creating a public mentionable select menu and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.publicRoleSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend PublicRoleSelectMenu<M>.() -> Unit): PublicRoleSelectMenu<M>

DSL function for creating a public role select menu and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.publicStringSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend PublicStringSelectMenu<M>.() -> Unit): PublicStringSelectMenu<M>

DSL function for creating a public string select menu and adding it to the current ComponentContainer.

Link copied to clipboard
suspend fun <M : ModalForm> ComponentContainer.publicUserSelectMenu(modal: () -> M?, row: Int? = null, builder: suspend PublicUserSelectMenu<M>.() -> Unit): PublicUserSelectMenu<M>

DSL function for creating a public user select menu and adding it to the current ComponentContainer.

Link copied to clipboard
open suspend fun remove(component: Component): Boolean

Remove the given component, and unregister it from the ComponentRegistry.

Link copied to clipboard
open suspend fun removeAll()

Remove all components, and unregister them from the ComponentRegistry.

Link copied to clipboard
open suspend fun replace(old: Component, new: Component): Boolean

Given two components, replace the old component with the new one and likewise handle registration.

open suspend fun replace(id: String, new: Component): Boolean

Given an old component ID and new component, replace the old component with the new one and likewise handle registration.

Link copied to clipboard
open suspend fun sort()

Sort all components in unsortedComponents by packing them into rows as tightly as possible.