Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MyraBot/voice

Repository files navigation

🎺 Voice

A Kotlin Discord Voice API wrapper kept very, very simple. This is for demonstration purpose only and shouldn't be used in production! I made this library to understand how the Voice API works and get a basic example down.

The library handles the voice sockets as well as the main gateway. Both are really simple and do not feature full support for everything.

Warning

πŸ—οΈ Example

The example uses Lavaplayer to get opus encoded audio.

suspend fun main() = coroutineScope {
 VoiceApi.apply {
 token = "YOUR_BOT_TOKEN"
 connectGateway()
 }.awaitReady()
 val playerManager = DefaultAudioPlayerManager()
 playerManager.registerSourceManager(YoutubeAudioSourceManager())
 val track = suspendCoroutine<AudioTrack> { c ->
 playerManager.loadItem(
 "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
 FunctionalResultHandler(
 { c.resume(it) },
 { c.resume(it.tracks.first()) },
 {},
 {}
 )
 )
 }
 val server = VoiceStateUpdate(
 guildId = "642809436515074053",
 channelId = "712567184727212094",
 selfMute = false,
 selfDeaf = false
 )
 val connection: VoiceConnection = VoiceApi.connect(server)
 connection.openConnection()
 val player = playerManager.createPlayer()
 player.playTrack(track)
 connection.udp?.audioProvider?.provide { player.provide()?.data }
 while (true) {
 }
}

πŸ“š Libraries used

About

🎺 Simple Discord Voice API wrapper

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /