All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.freya022.botcommands.api.components.AwaitableComponent.kt Maven / Gradle / Ivy

Go to download

A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.

The newest version!
package io.github.freya022.botcommands.api.components

import kotlinx.coroutines.TimeoutCancellationException
import net.dv8tion.jda.api.interactions.components.ComponentInteraction

interface AwaitableComponent : IdentifiableComponent {
    /**
     * Suspends until the component is used and all checks passed, and returns the event.
     *
     * @throws TimeoutCancellationException If the timeout set in the component builder has been reached
     */
    @JvmSynthetic
    suspend fun await(): T
}

/**
 * Suspends until the component is used and all checks passed, and returns the event,
 * or `null` if the timeout has been reached.
 */
@JvmSynthetic
suspend fun  AwaitableComponent.awaitOrNull(): T? = try {
    await()
} catch (e: TimeoutCancellationException) {
    null
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy