Skip to content

Latest commit

 

History

History

gateway

Kord gateway

A low-level implementation of discord's gateway.

Example usage

suspend fun main(args: Array<String>) {
    val token = args.firstOrNull() ?: error("token required")

    val gateway = DefaultGateway { // optional builder for custom configuration
        client = HttpClient {
            install(WebSockets)
        }
        reconnectRetry = LinearRetry(2.seconds, 20.seconds, 10)
        sendRateLimiter = IntervalRateLimiter(120, 60.seconds)
        dispatcher = Dispatchers.Default
    }

    gateway.events.filterIsInstance<MessageCreate>().onEach {
        val words = it.message.content.split(' ')
        when (words.firstOrNull()) {
            "!close" -> gateway.stop()
            "!detach" -> gateway.detach()
            "!status" -> when (words.getOrNull(1)) {
                "playing" -> gateway.editPresence {
                    status = PresenceStatus.Online
                    afk = false
                    playing("Kord")
                }
            }
        }
    }.launchIn(gateway)

    gateway.start(token) {
        @OptIn(PrivilegedIntent::class)
        intents += Intent.MessageContent
    }
}

Installation

See the root README for more information.

Gradle (Kotlin)

dependencies {
    implementation("dev.kord:kord-gateway:{version}")
}

Gradle (Groovy)

dependencies {
    implementation("dev.kord:kord-gateway:{version}")
}

Maven

<dependency>
    <groupId>dev.kord</groupId>
    <artifactId>kord-gateway-jvm</artifactId>
    <version>{version}</version>
</dependency>