diff --git a/src/main/java/org/camelia/studio/kiss/shot/acerola/audio/PlayerManager.java b/src/main/java/org/camelia/studio/kiss/shot/acerola/audio/PlayerManager.java index b57a055..f35b1ad 100644 --- a/src/main/java/org/camelia/studio/kiss/shot/acerola/audio/PlayerManager.java +++ b/src/main/java/org/camelia/studio/kiss/shot/acerola/audio/PlayerManager.java @@ -8,7 +8,6 @@ import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import java.util.HashMap; @@ -42,7 +41,7 @@ public class PlayerManager { public void loadAndPlay(GuildMessageChannel channel, String url) { final GuildMusicManager musicManager = getMusicManager(channel.getGuild()); - + audioPlayerManager.loadItemOrdered(musicManager, url, new AudioLoadResultHandler() { @Override public void trackLoaded(AudioTrack track) { diff --git a/src/main/java/org/camelia/studio/kiss/shot/acerola/commands/utils/PlayAudioCommand.java b/src/main/java/org/camelia/studio/kiss/shot/acerola/commands/utils/PlayAudioCommand.java index 26229c8..089ff1a 100644 --- a/src/main/java/org/camelia/studio/kiss/shot/acerola/commands/utils/PlayAudioCommand.java +++ b/src/main/java/org/camelia/studio/kiss/shot/acerola/commands/utils/PlayAudioCommand.java @@ -1,7 +1,10 @@ package org.camelia.studio.kiss.shot.acerola.commands.utils; +import net.dv8tion.jda.api.audio.hooks.ConnectionListener; +import net.dv8tion.jda.api.audio.hooks.ConnectionStatus; import net.dv8tion.jda.api.entities.GuildVoiceState; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; @@ -44,6 +47,23 @@ public class PlayAudioCommand implements ISlashCommand { AudioManager audioManager = event.getGuild().getAudioManager(); + audioManager.setConnectionListener(new ConnectionListener() { + @Override + public void onStatusChange(ConnectionStatus status) { + if (status == ConnectionStatus.CONNECTED) { + if (voiceState.getChannel().getType() == ChannelType.STAGE) { + voiceState.getChannel().asStageChannel().requestToSpeak().queue(speakSuccess -> { + audioManager.setConnectionListener(null); + }, error -> { + audioManager.setConnectionListener(null); + }); + } else { + audioManager.setConnectionListener(null); + } + } + } + }); + audioManager.openAudioConnection(voiceState.getChannel()); PlayerManager.getInstance().getMusicManager(event.getGuild()).audioPlayer.setVolume(25); PlayerManager.getInstance().loadAndPlay(event.getChannel().asGuildMessageChannel(), url); diff --git a/src/main/java/org/camelia/studio/kiss/shot/acerola/listeners/VoiceLeaveListener.java b/src/main/java/org/camelia/studio/kiss/shot/acerola/listeners/VoiceLeaveListener.java index c10becd..157b555 100644 --- a/src/main/java/org/camelia/studio/kiss/shot/acerola/listeners/VoiceLeaveListener.java +++ b/src/main/java/org/camelia/studio/kiss/shot/acerola/listeners/VoiceLeaveListener.java @@ -3,7 +3,7 @@ package org.camelia.studio.kiss.shot.acerola.listeners; import org.camelia.studio.kiss.shot.acerola.audio.PlayerManager; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.managers.AudioManager; @@ -19,7 +19,7 @@ public class VoiceLeaveListener extends ListenerAdapter { return; } - VoiceChannel botChannel = audioManager.getConnectedChannel().asVoiceChannel(); + AudioChannel botChannel = audioManager.getConnectedChannel(); // Compte le nombre de membres dans le canal (excluant les bots) long realMembersCount = botChannel.getMembers().stream()