Search in sources :

Example 16 with AudioManager

use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.

the class FancyPlay method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length > 1) {
        AudioManager audioManager = guild.getAudioManager();
        String url = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0], "");
        boolean shouldDeleteMessage = shouldDeleteMessages(guild);
        boolean implement = false;
        if (!audioManager.isConnected()) {
            VoiceChannel success = joinChannel(guild, guild.getMember(user), this, audioManager, channel);
            if (success != null) {
                loadAndPlay(message, user, this, (TextChannel) channel, url, success, false, false);
                implement = true;
            }
        } else {
            loadAndPlay(message, user, this, (TextChannel) sendTo(channel, guild), url, audioManager.getConnectedChannel(), false, false);
            implement = true;
        }
        if (implement) {
            if (shouldDeleteMessage) {
                try {
                    message.delete().queue();
                } catch (PermissionException ex) {
                    guild.getOwner().getUser().openPrivateChannel().queue(privateChannel -> {
                        privateChannel.sendMessage("Auto-deleting music play messages is enabled, " + "but you need to give me the `MANAGE MESSAGES` permission so I can " + "actually delete the messages.").queue();
                    });
                }
            }
        }
    } else
        sendTranslatedMessage("You need to specify a song name or URL", channel, user);
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) GuildUtils(tk.ardentbot.utils.discord.GuildUtils) Command(tk.ardentbot.core.executor.Command) Music(tk.ardentbot.commands.music.Music) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioManager(net.dv8tion.jda.core.managers.AudioManager)

Example 17 with AudioManager

use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.

the class MusicLeave method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    AudioManager audioManager = guild.getAudioManager();
    Member member = guild.getMember(user);
    if (audioManager.isConnected()) {
        if (UserUtils.hasManageServerOrStaff(member) || UserUtils.isBotCommander(member) || audioManager.getConnectedChannel().getMembers().size() == 2) {
            String name = audioManager.getConnectedChannel().getName();
            audioManager.closeAudioConnection();
            sendTranslatedMessage("Disconnected from {0}".replace("{0}", name), channel, user);
        } else
            sendTranslatedMessage("You need the Manage Server permission to do this", channel, user);
    } else
        sendTranslatedMessage("I'm not in a voice channel!", channel, user);
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager)

Aggregations

AudioManager (net.dv8tion.jda.core.managers.AudioManager)17 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)4 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)3 Command (tk.ardentbot.core.executor.Command)3 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)2 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)2 ArrayList (java.util.ArrayList)2 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)2 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)2 Music (tk.ardentbot.commands.music.Music)2 Music.getGuildAudioPlayer (tk.ardentbot.commands.music.Music.getGuildAudioPlayer)2 GuildUtils (tk.ardentbot.utils.discord.GuildUtils)2 AudioEventAdapter (com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter)1 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 AudioTrackEndReason (com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason)1 AudioTrackState (com.sedmelluq.discord.lavaplayer.track.AudioTrackState)1 RecommendationsRequest (com.wrapper.spotify.methods.RecommendationsRequest)1 TrackSearchRequest (com.wrapper.spotify.methods.TrackSearchRequest)1 Track (com.wrapper.spotify.models.Track)1 Collections (java.util.Collections)1