Lavakord is a coroutine based client for LavaLink mainly designed to work with Kord
Support discord: https://discord.gg/ZbmrRVpDwR
Both Kord and Lavalink.kt are 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.
Lavalink download: https://github.com/freyacodes/Lavalink
For now you also need this repo: https://maven.arbjerg.dev/snapshots You can get Lavakord from here: https://central.sonatype.com/search?namespace=dev.schlaubi.lavakord
You can create a Lavalink
object like this
val lavalink = kord.lavakord()
// or
val lavalink = kord.lavakord {
link {
autoReconnect = false
retry = linear(2.seconds, 60.seconds, 10)
}
}
You can obtain and use a Link
like this
val link = guild.getLink(lavalink)
link.connect(channel)
// use lavalink stuff like player
link.disconnect()
Lavakord provides a wrapper for the Lavalink Track loading API
You can load a Track by using Link.loadItem(query: String)
Since 0.3 Lavakord provides a Flow based way to listen for events.
val link: KordLink // = .../
val player = link.player
player.on<TrackStartEvent> {
channel.createMessage(track.info.asString())
}
For more info please use the example or Dokka docs
Since Lavakord 1.0 we use only Multiplatform Kotlin libraries but Ktor doesn't support Websockets when using Kotlin native yet see kordlib/kord#69 and ktorio/ktor#1215 for reference. Kord doesn't support Multiplatform because of the same issue as well
Since 2.0 JS is officially supported
Since 1.0 it should be possible to implement your own version of lavakord by implementing your own versions of the LavaKord and Link classes you can see a reference implementation in the kord package
Add the kord
artifact
Apart from Kord there also is a JDA implementation. You can use it like the following. (Requires jda
artifact)
var (lavakord, jda) = JDABuilder.createDefault("token").buildWithLavakord()
class Javakord {
var container = new LavakordJDABuilder(JDABuilder.createDefault("token")).build();
var jda = container.getJda();
var lavakord = container.getLavakord();
JavaLavakord javaLavakord = JavaInterop.createJavaInterface(lavakord);
}
The snippets work similarly for DefaultShardManagerBuilder
as well.
Lavakord provides a compatibility layer for coroutines based
on Java 8's CompletableFuture API
. To access that interface please use the JavaInterop
class. For all rest related features refer to the TrackUtil
and RoutePlannerUtil
classes. In order to use these methods please add the java
or jda-java
artifact
Full example can be found here
class Javakord {
Lavakord lavakord;// = <lavakord build mechanism>
JavaLavakord javaLavakord = JavaInterop.createJavaInterface(lavakord);
}