A low-level implementation of discord's gateway.
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
}
}
See the root README for more information.
dependencies {
implementation("dev.kord:kord-gateway:{version}")
}
dependencies {
implementation("dev.kord:kord-gateway:{version}")
}
<dependency>
<groupId>dev.kord</groupId>
<artifactId>kord-gateway-jvm</artifactId>
<version>{version}</version>
</dependency>