Search in sources :

Example 31 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project Vinny by kikkia.

the class Bot method checkVoiceLobby.

private void checkVoiceLobby(GuildVoiceUpdateEvent event) {
    Guild guild = event.getEntity().getGuild();
    VoiceSendHandler handler = getHandler(guild);
    AudioManager manager = guild.getAudioManager();
    // if there are no humans left, then leave
    int users = 0;
    for (Member member : manager.getConnectedChannel().getMembers()) {
        if (!member.getUser().isBot())
            users++;
    }
    if (manager.isConnected() && users < 1) {
        handler.stop();
        manager.closeAudioConnection();
    }
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) Guild(net.dv8tion.jda.api.entities.Guild) InternalGuild(com.bot.models.InternalGuild) VoiceSendHandler(com.bot.voice.VoiceSendHandler) Member(net.dv8tion.jda.api.entities.Member)

Example 32 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project Tux by Bakterio.

the class JoinCommand method invoke.

@Override
public void invoke(GuildMessageReceivedEvent e, String[] args) {
    final GuildVoiceState voiceState = e.getGuild().getSelfMember().getVoiceState();
    final GuildVoiceState memberVoiceState = e.getMember().getVoiceState();
    if (voiceState.inVoiceChannel()) {
        e.getChannel().sendMessage("I am already in " + voiceState.getChannel().getName() + " channel.").queue();
        return;
    }
    if (!memberVoiceState.inVoiceChannel()) {
        e.getChannel().sendMessage("You have to be in voice channel to invoke this command...").queue();
        return;
    }
    final AudioManager audioManager = e.getGuild().getAudioManager();
    audioManager.openAudioConnection(memberVoiceState.getChannel());
    e.getChannel().sendMessage("I am in!!!").queue();
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState)

Example 33 with AudioManager

use of net.dv8tion.jda.api.managers.AudioManager in project Tux by Bakterio.

the class LeaveCommand method invoke.

@Override
public void invoke(GuildMessageReceivedEvent e, String[] args) {
    final GuildVoiceState voiceState = e.getGuild().getSelfMember().getVoiceState();
    if (!voiceState.inVoiceChannel()) {
        e.getChannel().sendMessage("I can't leave, I am not in any voice channel!!!").queue();
        return;
    }
    final AudioManager audioManager = e.getGuild().getAudioManager();
    // TODO why tf is this not working?
    audioManager.closeAudioConnection();
    e.getChannel().sendMessage("See you around... :wink:").queue();
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) GuildVoiceState(net.dv8tion.jda.api.entities.GuildVoiceState)

Example 34 with AudioManager

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

the class JoinCmd method command.

@Override
public void command(SlashCommandEvent event) {
    VoiceChannel memberVoiceChannel = getChannel(event);
    Guild guild = getGuild(event);
    AudioManager audioManager = getAudioManager(guild);
    audioManager.openAudioConnection(memberVoiceChannel);
    event.replyEmbeds(MessageUtil.buildMessage("What's up!")).queue();
}
Also used : AudioManager(net.dv8tion.jda.api.managers.AudioManager) VoiceChannel(net.dv8tion.jda.api.entities.VoiceChannel) Guild(net.dv8tion.jda.api.entities.Guild)

Example 35 with AudioManager

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

the class PlayCmd method command.

@Override
public void command(SlashCommandEvent event) {
    OptionMapping option = event.getOption(MUSIC_ARG);
    String args = option.getAsString();
    logger.debug("PlayCmd loading track: {}", args);
    AudioPlayer audioPlayer = audioPlayerManager.createPlayer();
    audioPlayer.addListener(audioEventListener);
    Consumer<Message> success = (message) -> {
        Guild guild = event.getGuild();
        AudioManager audioManager = guild.getAudioManager();
        PlayResultHandler playResultHandler = new PlayResultHandler(audioPlayer, guild, audioManager, event, audioPlayerManager, eventWaiter, message, false, audioQueueService);
        audioPlayerManager.loadItemOrdered(event.getGuild(), args, playResultHandler);
    };
    event.replyEmbeds(MessageUtil.buildMessage("Searching...")).queue(interactionHook -> {
        interactionHook.retrieveOriginal().queue(success);
    });
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Message(net.dv8tion.jda.api.entities.Message) OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) MessageUtil(io.github.brendonmiranda.bot.clancy.util.MessageUtil) Logger(org.slf4j.Logger) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) AudioManager(net.dv8tion.jda.api.managers.AudioManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Consumer(java.util.function.Consumer) AudioQueueService(io.github.brendonmiranda.bot.clancy.service.AudioQueueService) Component(org.springframework.stereotype.Component) PlayResultHandler(io.github.brendonmiranda.bot.clancy.listener.PlayResultHandler) Guild(net.dv8tion.jda.api.entities.Guild) OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) AudioEventListener(io.github.brendonmiranda.bot.clancy.listener.AudioEventListener) Collections(java.util.Collections) AudioManager(net.dv8tion.jda.api.managers.AudioManager) Message(net.dv8tion.jda.api.entities.Message) PlayResultHandler(io.github.brendonmiranda.bot.clancy.listener.PlayResultHandler) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) 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