Skip to content

[Mirror of GitLab] A Kotlin client for Discord with a light wrapper on the REST APIs and a simple to use DSL for basic bots.

License

Notifications You must be signed in to change notification settings

DHuckaby/Diskord

 
 

Repository files navigation

Diskord

Maven Central Discord

A Kotlin client for Discord bots with a simple and concise DSL

Built as a lean client using coroutines that gets the intricacies of rate limits, async, and data models out of your way in a clean and easy to use SDK.

Feel free to submit a PR or an Issue and I'll address it ASAP.

Using Diskord? Send me a tweet about it! @JesseLCorbett or drop by our Discord server.

How do I import this?

Gradle

repositories {
    mavenCentral()
    jcenter() // Necessary for kotlinx.serialization, until it is published in maven central too
}

dependencies {
    // Only if gradle >= 5.3
    implementation 'com.jessecorbett:diskord:1.5.1'

    // Valid for all gradle versions
    implementation 'com.jessecorbett:diskord-jvm:1.5.1'
}

Maven

<dependency>
    <groupId>com.jessecorbett</groupId>
    <artifactId>diskord-jvm</artifactId>
    <version>1.5.1</version>
</dependency>

How do I use this?

Simply instantiate a bot using the bot DSL, such as in the examples below.

Any function in the scope of the DSL will have access to a ClientStore clientStore to access clients for the bot user.

Additionally, extensions on the bot DSL, like the command DSL, can be done simply by writing extension functions which hook into the bot DSL on instantiation.

You can find more examples here.

You can access the documentation here.

Ping Pong Example

const val BOT_TOKEN = "A-Totally-Real-Discord-Bot-Token"

suspend fun main() {
    bot(BOT_TOKEN) {
        commands {
            command("ping") {
                reply("pong")
                delete()
            }
        }
    }
}

Echo Example

const val BOT_TOKEN = "A-Totally-Real-Discord-Bot-Token"

suspend fun main() {
    bot(BOT_TOKEN) {
        commands {
            command("echo") {
                reply(words.drop(1).joinToString(" "))
                delete()
            }
        }
    }
}

Embed Example

const val BOT_TOKEN = "A-Totally-Real-Discord-Bot-Token"

suspend fun main() {
    bot(BOT_TOKEN) {
        // Defaults to using command prefix `.` if unspecified
        commands("!") {
            command("embed") {
                delete()
                reply {
                    text = "This is an embed"
                    title = "Embed title"
                    description = "You can declare all the things here"
                }
            }
        }
    }
}

Reaction Example

const val BOT_TOKEN = "A-Totally-Real-Discord-Bot-Token"

suspend fun main() {
    bot(BOT_TOKEN) {
        messageCreated {
            if (it.content.contains("diskord")) {
                it.react("💯")
            }
        }
    }
}

Combined Example

const val BOT_TOKEN = "A-Totally-Real-Discord-Bot-Token"

suspend fun main() {
    bot(BOT_TOKEN) {
        messageCreated {
            if (it.content.contains("diskord")) {
                it.react("💯")
            }
        }
        
        // Defaults to using command prefix `.`
        commands {
            command("ping") {
                reply("pong")
                delete()
            }
                
            command("echo") {
                reply(words.drop(1).joinToString(" "))
                delete()
            }            
        }
    }
}

FAQ

  • Does this support voice chat?
    • No, voice chat is not supported at this time. If you need it I recommend checking out JDA or Discord4J
  • Is this library done?
    • It still needs some tests written, but Diskord is actively maintained and API complete, so it should be safe to use
  • Can I contact you to ask a question/contribute to the project/report a bug/tell you this is all shit?
  • What if I'm hip and cool, and I want to use a newer more unstable exciting version?

Things to do

  • Add more testing
  • Voice support

About

[Mirror of GitLab] A Kotlin client for Discord with a light wrapper on the REST APIs and a simple to use DSL for basic bots.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%