Gateway

An implementation of the Discord Gateway and its lifecycle.

Allows consumers to receive events through events and send commands through send.

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
abstract val events: SharedFlow<Event>

The incoming events of the Gateway.

Link copied to clipboard
abstract val ping: StateFlow<Duration?>

The duration between the last Heartbeat and HeartbeatACK.

Functions

Link copied to clipboard
abstract suspend fun detach()

Close gateway and releases resources.

Link copied to clipboard
inline suspend fun Gateway.editPresence(builder: PresenceBuilder.() -> Unit)
Link copied to clipboard
inline fun <T : Event> Gateway.on(scope: CoroutineScope = this, crossinline consumer: suspend T.() -> Unit): Job

Convenience method that will invoke the consumer on every event T created by Gateway.events.

Link copied to clipboard

Executes the request on this gateway, returning a flow of GuildMembersChunk responses.

fun Gateway.requestGuildMembers(guildId: Snowflake, builder: RequestGuildMembersBuilder.() -> Unit = { requestAllMembers() }): Flow<GuildMembersChunk>

Executes a RequestGuildMembers command configured by the builder for the given guildId on this gateway, returning a flow of GuildMembersChunk responses.

Link copied to clipboard
abstract suspend fun send(command: Command)

Sends a Command to the gateway, suspending until the message has been sent.

Link copied to clipboard
abstract suspend fun start(configuration: GatewayConfiguration)

Starts a reconnection gateway connection with the given configuration. This function will suspend until the lifecycle of the gateway has ended.

Link copied to clipboard
inline suspend fun Gateway.start(token: String, config: GatewayConfigurationBuilder.() -> Unit = {})

Starts a reconnecting gateway connection with the given parameters. This function will suspend until the lifecycle of the gateway has ended.

Link copied to clipboard
abstract suspend fun stop()

Closes the Gateway and ends the current session, suspending until the underlying webSocket is closed.