All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.BaseVoiceChannelBehaviorExtensions.kt Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
@file:JvmName("VoiceBaseVoiceChannelBehavior")

package dev.kord.core.behavior.channel

import dev.kord.common.annotation.KordVoice
import dev.kord.core.entity.channel.VoiceChannel
import dev.kord.core.exception.GatewayNotFoundException
import dev.kord.voice.VoiceConnection
import dev.kord.voice.VoiceConnectionBuilder

/**
 * Connect to this [VoiceChannel] and create a [VoiceConnection] for this voice session.
 *
 * @param builder a builder for the [VoiceConnection].
 * @throws GatewayNotFoundException when there is no associated [dev.kord.gateway.Gateway] for the [dev.kord.core.entity.Guild] this channel is in.
 * @throws dev.kord.voice.exception.VoiceConnectionInitializationException when there was a problem retrieving voice information from Discord.
 * @return a [VoiceConnection] representing the connection to this [VoiceConnection].
 */
@KordVoice
public suspend fun BaseVoiceChannelBehavior.connect(builder: VoiceConnectionBuilder.() -> Unit): VoiceConnection {
    val voiceConnection = VoiceConnection(
        guild.gateway ?: GatewayNotFoundException.voiceConnectionGatewayNotFound(guildId),
        kord.selfId,
        id,
        guildId,
        builder
    )

    voiceConnection.connect()

    return voiceConnection
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy