• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

kordlib/kord: Idiomatic Kotlin Wrapper for The Discord API

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

kordlib/kord

开源软件地址(OpenSource Url):

https://github.com/kordlib/kord

开源编程语言(OpenSource Language):

Kotlin 95.9%

开源软件介绍(OpenSource Introduction):

Kord

Discord Download Github CI status (branch)

Kord is still in an experimental stage, as such we can't guarantee API stability between releases. While we'd love for you to try out our library, we don't recommend you use this in production just yet.

If you have any feedback, we'd love to hear it, hit us up on discord or write up an issue if you have any suggestions!

What is Kord

Kord is a coroutine-based, modularized implementation of the Discord API, written 100% in Kotlin.

Why use Kord

Kord was created as an answer to the frustrations of writing Discord bots with other JVM libraries, which either use thread-blocking code or verbose and scope restrictive reactive systems. We believe an API written from the ground up in Kotlin with coroutines can give you the best of both worlds: The conciseness of imperative code with the concurrency of reactive code.

Aside from coroutines, we also wanted to give the user full access to lower level APIs. Sometimes you have to do some unconventional things, and we want to allow you to do those in a safe and supported way.

Status of Kord

Right now Kord should provide a full mapping of the non-voice API. We're currently working on a testing library for easy bot testing against a semi mocked client as well as our own command system to facilitate more complex bot development.

Documentation

Installation

Replace {version} with the latest version number on maven central.

For Snapshots replace {version} with {branch}-SNAPSHOT

e.g: 0.7.x-SNAPSHOT

Download

Gradle (groovy)

repositories {
    mavenCentral()
    // Kord Snapshots Repository (Optional):
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}
dependencies {
    implementation("dev.kord:kord-core:{version}")
}

Gradle (kotlin)

repositories {
    mavenCentral()
    // Kord Snapshots Repository (Optional):
    maven("https://oss.sonatype.org/content/repositories/snapshots")
}

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

Maven

Kord Snapshots Repository (Optional):
<repository>
    <id>snapshots-repo</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <releases>
        <enabled>false</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

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

Modules

Core

A higher level API, combining rest and gateway, with additional (optional) caching. Unless you're writing your own abstractions, we'd recommend using this.

suspend fun main() {
    val kord = Kord("your bot token")
    val pingPong = ReactionEmoji.Unicode("\uD83C\uDFD3")

    kord.on<MessageCreateEvent> {
        if (message.content != "!ping") return@on

        val response = message.channel.createMessage("Pong!")
        response.addReaction(pingPong)

        delay(5000)
        message.delete()
        response.delete()
    }

    kord.login {
        @OptIn(PrivilegedIntent::class)
        intents += Intent.MessageContent
    }
}

Rest

A low level mapping of Discord's REST API. Requests follow Discord's rate limits.

suspend fun main() {
    val rest = RestClient("your bot token")
    val channelId = Snowflake(605212557522763787)

    rest.channel.createMessage(channelId) {
        content = "Hello Kord!"

        embed {
            color = Color(red = 0, green = 0, blue = 255)
            description = "Hello embed!"
        }
    }
}

Gateway

A low level mapping of Discord's Gateway, which maintains the connection and rate limits commands.

suspend fun main() {
    val gateway = DefaultGateway()

    gateway.on<MessageCreate> {
        println("${message.author.username}: ${message.content}")
        val words = message.content.split(' ')
        when (words.firstOrNull()) {
            "!close" -> gateway.stop()
            "!detach" -> gateway.detach()
        }
    }

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

Voice

A mapping of Discord's Voice Connection, which maintains the connection and handles audio transmission.

If you want to use voice, you need to enable the voice capability, which is only available for Gradle

dependencies {
    implementation("dev.kord", "core", "<version>") {
        capabilities {
            requireCapability("dev.kord:core-voice:<version>")
        }
    }
}
suspend fun main() {
    val kord = Kord("your token")
    val voiceChannel = kord.getChannelOf<VoiceChannel>(id = Snowflake(1))!!

    voiceChannel.connect {
        audioProvider { AudioFrame.fromData(/* your opus encoded audio */) }
    }

    kord.login()
}

FAQ

Will you support kotlin multi-platform

We will, there's an issue open to track the features we want/need to make a transition to MPP smooth.

When will you document your code

Yes.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap