Java Code Examples for net.dv8tion.jda.api.managers.AudioManager#isConnected()
The following examples show how to use
net.dv8tion.jda.api.managers.AudioManager#isConnected() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultAudioServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override public boolean isConnected(Guild guild) { if (lavaLink != null) { Link link = lavaLink.getLink(guild); return link.getState() == Link.State.CONNECTED || link.getState() == Link.State.CONNECTING; } else { AudioManager audioManager = guild.getAudioManager(); return audioManager != null && (audioManager.isConnected() || audioManager.isAttemptingToConnect()); } }
Example 2
Source File: Main.java From lavaplayer with Apache License 2.0 | 5 votes |
private static void connectToFirstVoiceChannel(AudioManager audioManager) { if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) { for (VoiceChannel voiceChannel : audioManager.getGuild().getVoiceChannels()) { audioManager.openAudioConnection(voiceChannel); break; } } }
Example 3
Source File: SoundPlayerImpl.java From DiscordSoundboard with Apache License 2.0 | 5 votes |
/** * Moves to the specified voice channel. * * @param channel - The channel specified. */ private void moveToChannel(VoiceChannel channel, Guild guild) { // boolean hasPermissionToSpeak = PermissionUtil.checkPermission(bot.getSelfUser(), Permission.VOICE_SPEAK); // if (hasPermissionToSpeak) { AudioManager audioManager = guild.getAudioManager(); if (audioManager.isConnected()) { if (audioManager.isAttemptingToConnect()) { audioManager.closeAudioConnection(); } audioManager.openAudioConnection(channel); } else { audioManager.openAudioConnection(channel); } int i = 0; int waitTime = 100; int maxIterations = 40; //Wait for the audio connection to be ready before proceeding. synchronized (this) { while (!audioManager.isConnected()) { try { wait(waitTime); i++; if (i >= maxIterations) { break; //break out if after 1 second it doesn't get a connection; } } catch (InterruptedException e) { LOG.warn("Waiting for audio connection was interrupted."); } } } // } else { // throw new SoundPlaybackException("The bot does not have permission to speak in the requested channel: " + channel.getName() + "."); // } }