Search in sources :

Example 16 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project Wylx by Wylx-Bot.

the class VoiceChannelProcessing method checkVoiceChannel.

private void checkVoiceChannel(long guildID) {
    GuildMusicManager guildMusicManager = WylxPlayerManager.getInstance().getGuildManager(guildID);
    AudioManager manager = Wylx.getInstance().getGuildAudioManager(guildID);
    AudioChannel channel = manager.getConnectedChannel();
    if (channel == null) {
        guildMusicManager.stop();
        return;
    }
    // Leave if we are the only user left
    if (manager.isConnected() && channel.getMembers().size() == 1) {
        logger.debug("Leaving {} due to inactivity", guildID);
        guildMusicManager.stop();
    }
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildMusicManager(Core.Music.GuildMusicManager) AudioChannel(net.dv8tion.jda.api.entities.AudioChannel)

Example 17 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project ascent_bot by FeroniK.

the class TrackScheduler method onTrackEnd.

@Override
public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
    if (endReason.mayStartNext) {
        if (this.isRepeating) {
            this.player.startTrack(track.makeClone(), false);
            return;
        }
        if (this.queue.isEmpty() && currentGuild != null) {
            AudioManager audioManager = currentGuild.getAudioManager();
            audioManager.closeAudioConnection();
            return;
        }
        nextTrack();
    }
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager)

Example 18 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project ascent_bot by FeroniK.

the class Leave method handle.

@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
    final TextChannel channel = ctx.getChannel();
    final Member member = ctx.getMember();
    final GuildVoiceState memberVoiceState = member.getVoiceState();
    GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
    musicManager.scheduler.isRepeating = false;
    musicManager.scheduler.queue.clear();
    musicManager.scheduler.player.startTrack(null, false);
    AudioManager audioManager = ctx.getGuild().getAudioManager();
    audioManager.closeAudioConnection();
    String desc = "Disconnected from " + memberVoiceState.getChannel().getAsMention();
    EmbedBuilder builder = Embeds.createBuilder("Disconnected", desc, "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
    channel.sendMessageEmbeds(builder.build()).queue();
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState) Member(net.dv8tion.jda.api.entities.Member)

Example 19 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project ascent_bot by FeroniK.

the class MusicCommand method handleMusicCommands.

@SuppressWarnings("ConstantConditions")
public static void handleMusicCommands(CommandContext ctx, ICommand cmd) {
    final TextChannel channel = ctx.getChannel();
    final Member selfMember = ctx.getSelfMember();
    GuildVoiceState selfVoiceState = selfMember.getVoiceState();
    final Member member = ctx.getMember();
    final GuildVoiceState memberVoiceState = member.getVoiceState();
    if (!memberVoiceState.inVoiceChannel()) {
        channel.sendMessageEmbeds(Embeds.notConnectedToVcEmbed(member).build()).queue();
        return;
    }
    if (cmd.isDjNeeded()) {
        Role dj = member.getRoles().stream().filter((role) -> role.getName().equalsIgnoreCase("DJ")).findFirst().orElse(null);
        boolean canInteract = ctx.getGuild().getSelfMember().canInteract(member);
        List<Member> collect = memberVoiceState.getChannel().getMembers().stream().filter((mem) -> !mem.getUser().isBot() && mem != member).collect(Collectors.toList());
        if (dj == null && canInteract && !collect.isEmpty()) {
            channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "You do not have the DJ Role in the server", null, null, null).build()).queue();
            return;
        }
    }
    AudioManager audioManager = ctx.getGuild().getAudioManager();
    audioManager.setSelfDeafened(true);
    if (!selfVoiceState.inVoiceChannel()) {
        if (cmd.getName().equalsIgnoreCase("leave")) {
            EmbedBuilder builder = Embeds.alreadyConnectedToVcEmbed(member);
            builder.setDescription("I am not connected to a voice channel");
            channel.sendMessageEmbeds(builder.build()).queue();
            return;
        } else // check if its a auto join command
        if (cmd.getName().equalsIgnoreCase("join") || cmd.getName().equalsIgnoreCase("play") || cmd.getName().equalsIgnoreCase("search") || cmd.getName().equalsIgnoreCase("scplay") || cmd.getName().equalsIgnoreCase("spotify")) {
            if (!selfMember.hasPermission(Permission.VOICE_CONNECT)) {
                channel.sendMessageEmbeds(Embeds.notEnoughPermsEmbed(member).build()).queue();
                return;
            }
            final VoiceChannel memberChannel = memberVoiceState.getChannel();
            audioManager.openAudioConnection(memberChannel);
            cmd.handle(ctx);
        } else {
            EmbedBuilder builder = Embeds.notInSameVcEmbed(member);
            builder.setDescription("Bot must be present in a VoiceChannel to use this Command");
            channel.sendMessageEmbeds(builder.build()).queue();
        }
        return;
    }
    if (!memberVoiceState.getChannel().getId().equals(selfVoiceState.getChannel().getId())) {
        channel.sendMessageEmbeds(Embeds.notInSameVcEmbed(member).setDescription("Already connected to a different channel").build()).queue();
        return;
    } else {
        if (cmd.getName().equalsIgnoreCase("join")) {
            channel.sendMessageEmbeds(Embeds.alreadyConnectedToVcEmbed(member).build()).queue();
            return;
        }
    }
    cmd.handle(ctx);
}
Also used : CommandContext(me.fero.ascent.commands.CommandContext) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) Embeds(me.fero.ascent.utils.Embeds) List(java.util.List) ICommand(me.fero.ascent.commands.ICommand) Permission(net.dv8tion.jda.api.Permission) AudioManager(net.dv8tion.jda.api.managers.AudioManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Collectors(java.util.stream.Collectors) GuildMusicManager(me.fero.ascent.lavaplayer.GuildMusicManager) PlayerManager(me.fero.ascent.lavaplayer.PlayerManager) AudioManager(net.dv8tion.jda.api.managers.AudioManager) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder)

Example 20 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project radio by toadless.

the class GuildMusicManager method join.

public void join(@NotNull VoiceChannel channel) {
    AudioManager manager = channel.getGuild().getAudioManager();
    manager.openAudioConnection(channel);
    player.setVolume(volume);
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager)

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