@@ -68,27 +68,36 @@ class PlayerController(
6868 return guild.voiceChannels.map { VoiceChannelDto (it.id, it.name) }
6969 }
7070
71+ private fun getChannel (guild : net.dv8tion.jda.api.entities.Guild , channelId : String? ): net.dv8tion.jda.api.entities.channel.middleman.AudioChannel ? {
72+ if (channelId == " owner" && botProps.ownerId.isNotEmpty()) {
73+ val member = guild.getMemberById(botProps.ownerId)
74+ return member?.voiceState?.channel
75+ }
76+ return if (! channelId.isNullOrEmpty()) {
77+ guild.getVoiceChannelById(channelId)
78+ } else {
79+ guild.voiceChannels.firstOrNull()
80+ }
81+ }
82+
7183 @PostMapping(" /player/{guildId}/play" )
7284 suspend fun play (@PathVariable guildId : Long , @RequestBody body : Map <String , String >) {
7385 val guild = shardManager.getGuildById(guildId) ? : throw RuntimeException (" Guild not found" )
7486 val properties = guildPropertiesService.getAwait(guildId)
7587 val player = playerRegistry.get(guild, properties)
88+
7689 // Ensure connected to voice
7790 val channelId = body[" channelId" ]
7891 if (! guild.audioManager.isConnected) {
79- val channel = if (channelId != null ) {
80- guild.getVoiceChannelById(channelId)
81- } else {
82- guild.voiceChannels.firstOrNull()
83- }
84-
92+ val channel = getChannel(guild, channelId)
8593 if (channel != null ) {
8694 guild.audioManager.openAudioConnection(channel)
8795 guild.audioManager.sendingHandler = player
8896 }
8997 }
9098
9199 var identifiers = (body[" url" ] ? : " " ).split(" |" )
100+ // ... (rest of play method logic)
92101 if (identifiers.isNotEmpty() && identifiers.first().isEmpty()) {
93102 identifiers = botProps.playlist.split(" |" )
94103 }
@@ -214,7 +223,7 @@ class PlayerController(
214223 suspend fun move (@PathVariable guildId : Long , @RequestBody body : Map <String , String >) {
215224 val guild = shardManager.getGuildById(guildId) ? : return
216225 val channelId = body[" channelId" ] ? : return
217- val channel = guild.getVoiceChannelById( channelId)
226+ val channel = getChannel(guild, channelId)
218227 if (channel != null ) {
219228 guild.audioManager.openAudioConnection(channel)
220229 }
0 commit comments