This guide is intended to get you started with Kord Extensions, from the ground up. To follow this guide, you'll need the following installed:
If you know what you're doing and just want to get started, you can use the following settings:
https://s01.oss.sonatype.org/content/repositories/snapshots
for snapshotscom.kotlindiscord.kord.extensions
kord-extensions
If you already know the basics of setting up a project and you'd rather skip the manual process, you can base your project on our template repository instead. This is also the project you'll end up building if you follow Guide: My First Bot.
The first thing you'll need to do is create a Gradle project. For this example, we'll use the group com.example.bot
, with the project name bot
. Start by opening a terminal (or command prompt on Windows) wherever you'd like to create your project, running gradle init
, and answering the questions it gives you:
> gradle init
Starting a Gradle Daemon (subsequent builds will be faster)
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) [1..6] 4
Split functionality across multiple subprojects?:
1: no - only one application project
2: yes - application and library projects
Enter selection (default: no - only one application project) [1..2] 1
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Kotlin) [1..2] 2
Project name (default: my-bot): bot
Source package (default: bot): com.example.bot
> Task :init
Get more help with your project: https://docs.gradle.org/7.1.1/samples/sample_building_kotlin_applications.html
Next, if you're not using the latest version of Gradle, update your wrapper using gradlew wrapper --gradle-version 7.3.3
(replacing 7.3.3 with the latest version from the Gradle releases page):
> gradlew wrapper --gradle-version 7.3.3
BUILD SUCCESSFUL in 32s
1 actionable task: 1 executed
Open the settings.gradle.kts
file that Gradle has created for you. It should look like this:
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/7.3.3/userguide/multi_project_builds.html
*/
rootProject.name = "bot"
include("app")
In-between the last two lines, add the following - this will enable Gradle's experimental version catalog feature, which will make it easier to work with dependencies. You can also remove the comment at the top of the file, if you wish.
enableFeaturePreview("VERSION_CATALOGS")
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("libs.versions.toml"))
}
}
}
Now, create a new file named libs.versions.toml
, containing the following:
[versions]
kotlin = "1.6.10" # Note: Plugin versions must be updated in the build.gradle.kts too
kord-extensions = "VERSION" # Replace VERSION with the version you want to use
[libraries]
kord-extensions = { module = "com.kotlindiscord.kord.extensions:kord-extensions", version.ref = "kord-extensions" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8" }
Next, inside the app
folder Gradle created for you, open build.gradle.kts
. It should look something like this:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Kotlin application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.3.3/userguide/building_java_projects.html
*/
plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.6.10"
// Apply the application plugin to add support for building a CLI application in Java.
application
}
repositories {
// Use JCenter for resolving dependencies.
jcenter()
}
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// This dependency is used by the application.
implementation("com.google.guava:guava:29.0-jre")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
application {
// Define the main class for the application.
mainClass.set("com.example.bot.AppKt")
}
Edit this file so it looks more like the following:
plugins {
application
// Note: Update this if you change the Kotlin version in libs.versions.toml
kotlin("jvm") version "1.6.10"
}
repositories {
google()
mavenCentral()
maven {
name = "Sonatype Snapshots"
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
}
dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kord.extensions)
}
application {
mainClass.set("com.example.bot.AppKt")
}
In app/src
, delete the test
folder for now. You can recreate it if you decide to add unit tests later, but most Discord bots will not be able to be fully unit tested.
Finally, ensure that it works by running gradlew build
. the output should be similar to the following:
> gradlew build
Type-safe dependency accessors is an incubating feature.
BUILD SUCCESSFUL in 3s
6 actionable tasks: 6 executed
Assuming you don't get any errors, you're ready to proceed with the next guide - My First Bot.