Search in sources :

Example 1 with GuildMusicManager

use of com.discord.bot.audioplayer.GuildMusicManager in project discord-bot-reddit-java by Glaxier0.

the class LeaveCommand method execute.

@Override
public void execute(SlashCommandInteractionEvent event) {
    GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
    GuildVoiceState userVoiceState = event.getMember().getVoiceState();
    if (utils.channelControl(botVoiceState, userVoiceState)) {
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event);
        AudioManager audioManager = event.getGuild().getAudioManager();
        musicManager.scheduler.player.stopTrack();
        musicManager.scheduler.queue.clear();
        audioManager.closeAudioConnection();
        event.replyEmbeds(new EmbedBuilder().setDescription("Bye.").build()).queue();
    } else {
        event.replyEmbeds(new EmbedBuilder().setDescription("Please be in a same voice channel as bot.").setColor(Color.RED).build()).queue();
    }
    net.dv8tion.jda.api.entities.User user = event.getUser();
    utils.counter(user.getId(), user.getAsTag());
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(com.discord.bot.audioplayer.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState)

Example 2 with GuildMusicManager

use of com.discord.bot.audioplayer.GuildMusicManager in project discord-bot-reddit-java by Glaxier0.

the class PlayCommand method playMusic.

private void playMusic(SlashCommandInteractionEvent event, List<String> youtubeLinks) {
    AudioChannel userChannel = event.getMember().getVoiceState().getChannel();
    AudioChannel botChannel = event.getGuild().getSelfMember().getVoiceState().getChannel();
    boolean isUserInVoiceChannel = event.getMember().getVoiceState().inAudioChannel();
    boolean isBotInVoiceChannel = event.getGuild().getSelfMember().getVoiceState().inAudioChannel();
    if (isUserInVoiceChannel && !youtubeLinks.isEmpty()) {
        if (!isBotInVoiceChannel) {
            GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event);
            musicManager.scheduler.player.destroy();
            musicManager.scheduler.queue.clear();
            event.getGuild().getAudioManager().openAudioConnection(userChannel);
            botChannel = userChannel;
        }
        if (botChannel.equals(userChannel)) {
            int trackSize = youtubeLinks.size();
            if (trackSize > 1) {
                PlayerManager.getInstance().loadMultipleAndPlay(event, youtubeLinks);
            } else if (trackSize == 1) {
                PlayerManager.getInstance().loadAndPlay(event, youtubeLinks.get(0));
            }
        }
    }
}
Also used : AudioChannel(net.dv8tion.jda.api.entities.AudioChannel) GuildMusicManager(com.discord.bot.audioplayer.GuildMusicManager)

Example 3 with GuildMusicManager

use of com.discord.bot.audioplayer.GuildMusicManager in project discord-bot-reddit-java by Glaxier0.

the class ShuffleCommand method execute.

@Override
public void execute(SlashCommandInteractionEvent event) {
    GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
    GuildVoiceState userVoiceState = event.getMember().getVoiceState();
    if (utils.channelControl(botVoiceState, userVoiceState)) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event);
        List<AudioTrack> trackList = new ArrayList<>(musicManager.scheduler.queue);
        if (trackList.size() > 1) {
            Collections.shuffle(trackList);
            musicManager.scheduler.queue.clear();
            for (AudioTrack track : trackList) {
                musicManager.scheduler.queue(track);
            }
            embedBuilder.setDescription("Queue shuffled").setColor(Color.GREEN);
        } else {
            embedBuilder.setDescription("Queue size have to be at least two.").setColor(Color.RED);
        }
        event.replyEmbeds(embedBuilder.build()).queue();
    } else {
        event.replyEmbeds(new EmbedBuilder().setDescription("Please be in a same voice channel as bot.").setColor(Color.RED).build()).queue();
    }
    net.dv8tion.jda.api.entities.User user = event.getUser();
    utils.counter(user.getId(), user.getAsTag());
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(com.discord.bot.audioplayer.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 4 with GuildMusicManager

use of com.discord.bot.audioplayer.GuildMusicManager in project discord-bot-reddit-java by Glaxier0.

the class SwapCommand method execute.

@Override
public void execute(SlashCommandInteractionEvent event) {
    GuildVoiceState botVoiceState = event.getGuild().getSelfMember().getVoiceState();
    GuildVoiceState userVoiceState = event.getMember().getVoiceState();
    if (utils.channelControl(botVoiceState, userVoiceState)) {
        GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event);
        List<AudioTrack> trackList = new ArrayList<>(musicManager.scheduler.queue);
        if (trackList.size() > 1) {
            int first = event.getOption("songnum1").getAsInt() - 1;
            int second = event.getOption("songnum2").getAsInt() - 1;
            try {
                AudioTrack temp = trackList.get(first);
                trackList.set(first, trackList.get(second));
                trackList.set(second, temp);
            } catch (Exception e) {
                event.replyEmbeds(new EmbedBuilder().setDescription("Please enter a valid queue ids for both of the songs.").setColor(Color.RED).build()).queue();
                return;
            }
            musicManager.scheduler.queue.clear();
            for (AudioTrack track : trackList) {
                musicManager.scheduler.queue(track);
            }
            event.replyEmbeds(new EmbedBuilder().setDescription("Successfully swapped order of two songs").setColor(Color.GREEN).build()).queue();
        } else if (trackList.size() == 1) {
            event.replyEmbeds(new EmbedBuilder().setDescription("There is only one song in queue.").setColor(Color.RED).build()).queue();
        } else {
            event.replyEmbeds(new EmbedBuilder().setDescription("Queue is empty.").setColor(Color.RED).build()).queue();
        }
    } else {
        event.replyEmbeds(new EmbedBuilder().setDescription("Please be in a same voice channel as bot.").setColor(Color.RED).build()).queue();
    }
    net.dv8tion.jda.api.entities.User user = event.getUser();
    utils.counter(user.getId(), user.getAsTag());
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(com.discord.bot.audioplayer.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) ArrayList(java.util.ArrayList) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Aggregations

GuildMusicManager (com.discord.bot.audioplayer.GuildMusicManager)4 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)3 GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)3 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 ArrayList (java.util.ArrayList)2 AudioChannel (net.dv8tion.jda.api.entities.AudioChannel)1 AudioManager (net.dv8tion.jda.api.managers.AudioManager)1