It's that time again

It's that time where I need to make another discord bot, where can I look to get started with voice?
52 Replies
Shaun
ShaunOP7d ago
Oh nevermind, it seems discord bots cannot actually listen to audio...
gdude
gdude7d ago
they can in the gradle plugin, you can do kordEx { bot { voice = true } } if you're not using the gradle plugin, you already have the dependencies you need for voice you'll need to use Kord's APIs for voice they have no docs for it other than "use lavaplayer/lavalink for a music bot"
Shaun
ShaunOP7d ago
Oh shit nice
gdude
gdude7d ago
so you're going to have to do some messing around
Shaun
ShaunOP7d ago
My friend lying to me
gdude
gdude7d ago
yeah no they absolutely can
gdude
gdude7d ago
Craig
The multi-track recording bot for Discord.
gdude
gdude7d ago
I used this for ages it's definitely a thing
Shaun
ShaunOP7d ago
Yeah I just tried this out too Good to know How do I get the Kord channel ? So I can connect to it? val channel = member?.getVoiceState()?.getChannelOrNull() ?: return@action
gdude
gdude7d ago
you get it like you get any other channel generally from the guild object though for a specific member you use the voice state yeah
Shaun
ShaunOP7d ago
But I can't call connect on that result like the example omg pls remove slow mode in forum channels its driving me crazy already
gdude
gdude7d ago
did you reload your dependencies when you updated your plugin config?
Shaun
ShaunOP7d ago
I didn't update the config I wasn't sure where to put that string
gdude
gdude7d ago
are you using the kordex gradle plugin?
Shaun
ShaunOP7d ago
No(t yet)
gdude
gdude7d ago
ah, then you should already depend on the kord voice module honestly I haven't used the voice API so I'm not really sure what you need @SchlaubiBus would know
SchlaubiBus
SchlaubiBus7d ago
They can, it's just not officially supported
Shaun
ShaunOP7d ago
I added
implementation("dev.kord:kord-voice:0.15.0")
implementation("dev.kord:kord-voice-core:0.15.0")
implementation("dev.kord:kord-voice:0.15.0")
implementation("dev.kord:kord-voice-core:0.15.0")
And still can't connect
gdude
gdude7d ago
you don't need a Kord dependency and you almost certainly shouldn't add one
SchlaubiBus
SchlaubiBus7d ago
What's your code
gdude
gdude7d ago
KordEx provides the version it needs
Shaun
ShaunOP7d ago
Is this not you saying to add it?
gdude
gdude7d ago
no, that's me saying you already depend on it
Shaun
ShaunOP7d ago
I'm not using the plugin
gdude
gdude7d ago
which is why you're already depending on it yeah
Shaun
ShaunOP7d ago
Why can't I call connect then? BaseVoiceChannelBehavior doesn't have any functions on it
gdude
gdude7d ago
maybe you need to cast it using the of or ofOrNull functions? I dunno
Shaun
ShaunOP7d ago
ephemeralSlashCommand {
name = "join"
description = "GET JIM IN HERE"

action {
val channel = member?.getVoiceState()?.getChannelOrNull()
?: return@action


}
}
ephemeralSlashCommand {
name = "join"
description = "GET JIM IN HERE"

action {
val channel = member?.getVoiceState()?.getChannelOrNull()
?: return@action


}
}
gdude
gdude7d ago
ah you're on kordex 2.2 or earlier as well that's fine tho
SchlaubiBus
SchlaubiBus7d ago
GitHub
kord/core-voice/src/main/kotlin/BaseVoiceChannelBehaviorExtensions....
Idiomatic Kotlin Wrapper for The Discord API. Contribute to kordlib/kord development by creating an account on GitHub.
SchlaubiBus
SchlaubiBus7d ago
Its kinda hard to give more help on the limited info
Shaun
ShaunOP7d ago
I don't have that class on my cp I don't have voice-core
gdude
gdude7d ago
you depend on kordex, so remove both kord deps and then reload deps in the sidebar otherwise you're gonna have weird stuff happen
Shaun
ShaunOP7d ago
I have
gdude
gdude7d ago
hmm which version of kordex is this?
Shaun
ShaunOP7d ago
1.9.0-SNAPSHOT
gdude
gdude7d ago
out of date by a fair bit but that does include a core-voice dependency
Shaun
ShaunOP7d ago
Am I missing something?
dependencies {
implementation("ch.qos.logback:logback-core:1.5.6")
implementation("ch.qos.logback:logback-classic:1.5.6")
implementation("com.aallam.openai:openai-client:3.8.1")

implementation("com.kotlindiscord.kord.extensions:kord-extensions:$kordexVersion")
implementation("com.kotlindiscord.kord.extensions:unsafe:$kordexVersion")

testImplementation(kotlin("test"))
}
dependencies {
implementation("ch.qos.logback:logback-core:1.5.6")
implementation("ch.qos.logback:logback-classic:1.5.6")
implementation("com.aallam.openai:openai-client:3.8.1")

implementation("com.kotlindiscord.kord.extensions:kord-extensions:$kordexVersion")
implementation("com.kotlindiscord.kord.extensions:unsafe:$kordexVersion")

testImplementation(kotlin("test"))
}
gdude
gdude7d ago
no that seems fine for that version it looks like that extension function has been around for at least a year
Shaun
ShaunOP7d ago
I've really broken it now Cannot access class 'dev. kord. core. behavior. MemberBehavior'. Check your module classpath for missing or conflicting dependencies
gdude
gdude7d ago
reload gradle normally again IJ brr OK, 1.9.0-SNAPSHOT was released on july 1st 2024 and that kord extension.. april 5th 2023 yeah it should be there you could check the dependencies gradle task, the dep should be there I need to get ready to go out but yeah everything should be present
Shaun
ShaunOP7d ago
> Could not find dev.kord:kord-core-voice:0.15.0-SNAPSHOT.
gdude
gdude7d ago
Ah yeah that's right
Shaun
ShaunOP7d ago
That is not in my build gradle lol
gdude
gdude7d ago
Sonatype killed the dependency I forgot Try adding repo.kord.dev/snapshots to your repos
Shaun
ShaunOP7d ago
Like this?
maven {
name = "Kord"
url = uri("repo.kord.dev/snapshots")
}
maven {
name = "Kord"
url = uri("repo.kord.dev/snapshots")
}
gdude
gdude7d ago
Well with the https://
Shaun
ShaunOP7d ago
Oh yeah
gdude
gdude7d ago
I'm on mobile
Shaun
ShaunOP7d ago
Na I shoulda assumed that haha
gdude
gdude7d ago
Put it as the last repo So you're not slamming it for your other deps
Shaun
ShaunOP7d ago
Okay so does anyone know how I can listen for audio I can play audio okay Oh I found the incoming audio frames flow Doesn't seem to collect anything... I think there might be a bug Because connection.streams.ssrcToUser and incomingUserStreams don't work Well it's only set if I leave and rejoin the channel
OpusFile(baos).use { opusFile ->
opusFile.info.setSampleRate(48000)
opusFile.info.numChannels = 2
it.map { it.second }
.map { decodePacket(it.data) }
.forEach {
val bytes = shortBufferToByteBuffer(it)
val audioData = OpusAudioData(bytes)
opusFile.writeAudioData(audioData)
}
}
FileOutputStream("test.ogg").use {
baos.writeTo(it)
}
OpusFile(baos).use { opusFile ->
opusFile.info.setSampleRate(48000)
opusFile.info.numChannels = 2
it.map { it.second }
.map { decodePacket(it.data) }
.forEach {
val bytes = shortBufferToByteBuffer(it)
val audioData = OpusAudioData(bytes)
opusFile.writeAudioData(audioData)
}
}
FileOutputStream("test.ogg").use {
baos.writeTo(it)
}
Want results from more Discord servers?
Add your server