Search in sources :

Example 1 with AudioPlayerSendHandler

use of io.github.aquerr.futrzakbot.audio.handler.AudioPlayerSendHandler in project FutrzakBot by Aquerr.

the class PlayCommand method execute.

@Override
public boolean execute(Member member, TextChannel textChannel, List<String> args) {
    Guild guild = textChannel.getGuild();
    GuildVoiceState guildVoiceState = member.getVoiceState();
    VoiceChannel voiceChannel = guildVoiceState.getChannel();
    if (voiceChannel == null) {
        textChannel.sendMessage("Aby użyć tej komendy musisz być na kanale głosowym!").complete();
    } else {
        AudioManager audioManager = guild.getAudioManager();
        if (audioManager.getSendingHandler() == null) {
            audioManager.setSendingHandler(new AudioPlayerSendHandler(this.futrzakAudioPlayerManager.getOrCreateAudioPlayer(guild.getIdLong()).getInternalAudioPlayer()));
        }
        audioManager.openAudioConnection(voiceChannel);
        String songName = args.get(0);
        this.futrzakAudioPlayerManager.queue(guild.getIdLong(), textChannel, songName);
    }
    return true;
}
Also used : AudioPlayerSendHandler(io.github.aquerr.futrzakbot.audio.handler.AudioPlayerSendHandler) AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild)

Example 2 with AudioPlayerSendHandler

use of io.github.aquerr.futrzakbot.audio.handler.AudioPlayerSendHandler in project FutrzakBot by Aquerr.

the class SlashCommandListener method onSlashCommand.

@Override
public void onSlashCommand(SlashCommandEvent event) {
    if (event.getName().equals("player")) {
        if (event.getOption("song") != null) {
            GuildVoiceState guildVoiceState = event.getMember().getVoiceState();
            VoiceChannel voiceChannel = guildVoiceState.getChannel();
            if (voiceChannel == null) {
                event.reply("Aby użyć tej komendy musisz być na kanale głosowym!").queue();
            }
            Guild guild = event.getGuild();
            AudioManager audioManager = guild.getAudioManager();
            audioManager.setSendingHandler(new AudioPlayerSendHandler(this.futrzakAudioPlayerManager.getOrCreateAudioPlayer(guild.getIdLong()).getInternalAudioPlayer()));
            audioManager.openAudioConnection(voiceChannel);
            this.futrzakAudioPlayerManager.queue(event.getGuild().getIdLong(), event.getTextChannel(), event.getOption("song").getAsString());
        }
        event.reply("Futrzak Song Player").addActionRow(// Button with only a label
        Button.primary("queue", "View Song Queue"), // Button with only an emoji
        Button.success("next", ":track_next:")).queue();
    }
}
Also used : AudioPlayerSendHandler(io.github.aquerr.futrzakbot.audio.handler.AudioPlayerSendHandler) AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild)

Aggregations

AudioPlayerSendHandler (io.github.aquerr.futrzakbot.audio.handler.AudioPlayerSendHandler)2 Guild (net.dv8tion.jda.api.entities.Guild)2 GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)2 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)2 AudioManager (net.dv8tion.jda.api.managers.AudioManager)2