Search in sources :

Example 11 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project clancy by brendonmiranda.

the class MusicCmd method execute.

@Override
protected void execute(SlashCommandEvent event) {
    AudioManager audioManager = getAudioManager(event.getGuild());
    VoiceChannel memberVoiceChannel = getChannel(event);
    /*
		 * To execute any music command the bot needs to be in a voice channel. It
		 * validates this. A voice channel is reached by the bot through the Join command.
		 */
    if (audioManager.getConnectedChannel() == null) {
        event.replyEmbeds(MessageUtil.buildMessage("Type `/join`")).queue();
        return;
    }
    /*
		 * It validates if the member who trigger the event is present in a voice channel.
		 */
    if (memberVoiceChannel == null) {
        event.replyEmbeds(MessageUtil.buildMessage("You must be in a voice channel.")).queue();
        return;
    }
    command(event);
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel)

Example 12 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project Emolga by TecToast.

the class StartClippingCommand method process.

@Override
public void process(GuildCommandEvent e) {
    AudioManager am = e.getGuild().getAudioManager();
    am.openAudioConnection(e.getMember().getVoiceState().getChannel());
    clips.put(e.getGuild().getIdLong(), new CircularFifoQueue<>(1500));
    am.setReceivingHandler(new AudioReceiveHandler() {

        @Override
        public boolean canReceiveCombined() {
            return true;
        }

        @Override
        public boolean canReceiveUser() {
            return false;
        }

        @Override
        public void handleCombinedAudio(@NotNull CombinedAudio audio) {
            clips.get(e.getGuild().getIdLong()).add(audio.getAudioData(1.0));
        }

        @Override
        public boolean includeUserInCombinedAudio(@NotNull User user) {
            return true;
        }
    });
    e.reply("Sehr interessant was ihr so redet \uD83D\uDC40");
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) AudioReceiveHandler(net.dv8tion.jda.api.audio.AudioReceiveHandler) User(net.dv8tion.jda.api.entities.User) CombinedAudio(net.dv8tion.jda.api.audio.CombinedAudio)

Example 13 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project Papilertus by Handschrift.

the class SkipCommand method execute.

@Override
protected void execute(SlashCommandEvent slashCommandEvent) {
    if (slashCommandEvent.getGuild() == null) {
        slashCommandEvent.reply("You can only execute this command in a server").setEphemeral(true).queue();
        return;
    }
    final AudioManager manager = slashCommandEvent.getGuild().getAudioManager();
    final Member executor = slashCommandEvent.getMember();
    if (!executor.getVoiceState().inVoiceChannel() || !executor.getVoiceState().getChannel().getId().equals(manager.getConnectedChannel().getId())) {
        // Check if member is NOT in the same channel
        slashCommandEvent.reply("You have to be in the same voice channel!").setEphemeral(true).queue();
        return;
    }
    final EmbedBuilder builder = new EmbedBuilder();
    final GuildMusicManager guildManager = getGuildAudioPlayer(slashCommandEvent.getGuild());
    guildManager.getScheduler().nextTrack();
    builder.setDescription("Skipped to the next track");
    slashCommandEvent.replyEmbeds(builder.build()).queue();
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(com.musicplayer.audio.GuildMusicManager) Member(net.dv8tion.jda.api.entities.Member)

Example 14 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager 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 15 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager 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

AudioManager (net.dv8tion.jda.api.managers.AudioManager)48 GuildVoiceState (net.dv8tion.jda.api.entities.GuildVoiceState)12 Member (net.dv8tion.jda.api.entities.Member)10 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)9 Guild (net.dv8tion.jda.api.entities.Guild)9 List (java.util.List)8 VoiceChannel (net.dv8tion.jda.api.entities.VoiceChannel)8 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)5 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)4 Nonnull (javax.annotation.Nonnull)4 GuildMusicManager (me.fero.ascent.lavaplayer.GuildMusicManager)4 Permission (net.dv8tion.jda.api.Permission)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 net.dv8tion.jda.api.entities (net.dv8tion.jda.api.entities)3 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)3