net.dv8tion.jda.api.entities.VoiceChannel Java Examples
The following examples show how to use
net.dv8tion.jda.api.entities.VoiceChannel.
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: AudioCommand.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String content) throws DiscordException { Member member = message.getMember(); if (member == null) { return false; } if (!featureSetService.isAvailable(message.getGuild())) { discordService.sendBonusMessage(message.getChannel().getIdLong()); return false; } if (!playerService.hasAccess(member)) { throw new ValidationException("discord.command.audio.missingAccess"); } if (isActiveOnly() && !playerService.isActive(message.getGuild())) { messageManager.onMessage(message.getChannel(), "discord.command.audio.notStarted"); return false; } if (isChannelRestricted() && !playerService.isInChannel(member)) { VoiceChannel channel = playerService.getChannel(member); throw new ValidationException("discord.command.audio.joinChannel", channel != null ? channel.getName() : "unknown"); } return doInternal(message, context, content); }
Example #2
Source File: PlayerServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override @Transactional public VoiceChannel getDesiredChannel(Member member) { MusicConfig musicConfig = musicConfigService.get(member.getGuild()); VoiceChannel channel = null; if (musicConfig != null) { if (musicConfig.isUserJoinEnabled() && member.getVoiceState() != null && member.getVoiceState().inVoiceChannel()) { channel = member.getVoiceState().getChannel(); } if (channel == null && musicConfig.getChannelId() != null) { channel = member.getGuild().getVoiceChannelById(musicConfig.getChannelId()); } } if (channel == null) { channel = discordService.getDefaultMusicChannel(member.getGuild().getIdLong()); } return channel; }
Example #3
Source File: PlayerServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public VoiceChannel connectToChannel(PlaybackInstance instance, Member member) throws DiscordException { VoiceChannel channel = getDesiredChannel(member); if (channel == null) { return null; } if (!channel.getGuild().getSelfMember().hasPermission(channel, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK)) { throw new DiscordException("discord.global.voice.noAccess"); } try { lavaAudioService.openConnection(instance.getPlayer(), channel); } catch (InsufficientPermissionException e) { throw new DiscordException("discord.global.voice.noAccess", e); } return channel; }
Example #4
Source File: WebSocketClient.java From JDA with Apache License 2.0 | 6 votes |
public void queueAudioReconnect(VoiceChannel channel) { locked("There was an error queueing the audio reconnect", () -> { final long guildId = channel.getGuild().getIdLong(); ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) { // If no request, then just reconnect request = new ConnectionRequest(channel, ConnectionStage.RECONNECT); queuedAudioConnections.put(guildId, request); } else { // If there is a request we change it to reconnect, no matter what it is request.setStage(ConnectionStage.RECONNECT); } // in all cases, update to this channel request.setChannel(channel); }); }
Example #5
Source File: GuildInfoQueueListener.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@RabbitListener(queues = RabbitConfiguration.QUEUE_GUILD_INFO_REQUEST) public GuildDto getGuildInfo(Long guildId) { Guild guild = getGuildById(guildId); if (guild == null) { return GuildDto.EMPTY; } GuildDto dto = discordMapperService.getGuildDto(guild); if (CollectionUtils.isNotEmpty(dto.getRoles())) { // remove public @everyone role dto.getRoles().removeIf(e -> guild.getId().equals(e.getId())); } dto.setFeatureSets(featureSetService.getByGuild(guildId)); dto.setOnlineCount(guild.getMembers().stream() .filter(m -> m.getOnlineStatus() != OFFLINE && m.getOnlineStatus() != UNKNOWN).count()); VoiceChannel defaultMusicChannel = discordService.getDefaultMusicChannel(guildId); if (defaultMusicChannel != null) { dto.setDefaultMusicChannelId(defaultMusicChannel.getId()); } return dto; }
Example #6
Source File: CheckOwnerQueueListener.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@RabbitListener(queues = RabbitConfiguration.QUEUE_CHECK_OWNER_REQUEST) public boolean isAdministrator(CheckOwnerRequest request) { Guild guild = null; switch (request.getType()) { case TEXT: TextChannel textChannel = discordService.getTextChannelById(request.getChannelId()); if (textChannel != null) { guild = textChannel.getGuild(); } break; case VOICE: VoiceChannel voiceChannel = discordService.getVoiceChannelById(request.getChannelId()); if (voiceChannel != null) { guild = voiceChannel.getGuild(); } break; } if (guild == null) { return true; } Member member = guild.getMemberById(request.getUserId()); if (member == null) { return false; } return member.isOwner() || member.hasPermission(Permission.ADMINISTRATOR); }
Example #7
Source File: AudioCmdUtils.java From MantaroBot with GNU General Public License v3.0 | 6 votes |
public static CompletionStage<Void> openAudioConnection(GuildMessageReceivedEvent event, JdaLink link, VoiceChannel userChannel, I18nContext lang) { if (userChannel.getUserLimit() <= userChannel.getMembers().size() && userChannel.getUserLimit() > 0 && !event.getGuild().getSelfMember().hasPermission(Permission.MANAGE_CHANNEL)) { event.getChannel().sendMessageFormat(lang.get("commands.music_general.connect.full_channel"), EmoteReference.ERROR).queue(); return completedFuture(null); } try { //This used to be a CompletableFuture that went through a listener which is now useless bc im 99% sure you can't listen to the connection status on LL. joinVoiceChannel(link, userChannel); event.getChannel().sendMessageFormat(lang.get("commands.music_general.connect.success"), EmoteReference.CORRECT, userChannel.getName()).queue(); return completedFuture(null); } catch (NullPointerException e) { e.printStackTrace(); event.getChannel().sendMessageFormat(lang.get("commands.music_general.connect.non_existent_channel"), EmoteReference.ERROR).queue(); //Reset custom channel. DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild()); dbGuild.getData().setMusicChannel(null); dbGuild.saveAsync(); CompletableFuture<Void> future = new CompletableFuture<>(); future.completeExceptionally(e); return future; } }
Example #8
Source File: Network.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
public static Network with(Set<Player> players) { DiscordSRV.debug("Network being made for " + players); boolean allowVAD = DiscordSRV.config().getBoolean("Network.Allow voice activation detection"); List<Permission> allowedPermissions; if (allowVAD) { allowedPermissions = Arrays.asList(Permission.VOICE_SPEAK, Permission.VOICE_USE_VAD); } else { allowedPermissions = Collections.singletonList(Permission.VOICE_SPEAK); } VoiceChannel channel = (VoiceChannel) VoiceModule.getCategory().createVoiceChannel(UUID.randomUUID().toString()) .addPermissionOverride( VoiceModule.getGuild().getPublicRole(), allowedPermissions, Collections.singleton(Permission.VOICE_CONNECT) ) .complete(); return new Network(channel, players); }
Example #9
Source File: AudioManagerImpl.java From JDA with Apache License 2.0 | 6 votes |
private void checkChannel(VoiceChannel channel, Member self) { EnumSet<Permission> perms = Permission.getPermissions(PermissionUtil.getEffectivePermission(channel, self)); if (!perms.contains(Permission.VOICE_CONNECT)) throw new InsufficientPermissionException(channel, Permission.VOICE_CONNECT); final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set! if (userLimit > 0 && !perms.contains(Permission.ADMINISTRATOR)) { // Check if we can actually join this channel // - If there is a userlimit // - If that userlimit is reached // - If we don't have voice move others permissions // VOICE_MOVE_OTHERS allows access because you would be able to move people out to // open up a slot anyway if (userLimit <= channel.getMembers().size() && !perms.contains(Permission.VOICE_MOVE_OTHERS)) { throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS, "Unable to connect to VoiceChannel due to userlimit! Requires permission VOICE_MOVE_OTHERS to bypass"); } } }
Example #10
Source File: LavalinkTest.java From Lavalink-Client with MIT License | 6 votes |
private static void ensureNotConnected(JdaLavalink lavalink, VoiceChannel voiceChannel) { Link link = lavalink.getLink(voiceChannel.getGuild()); link.disconnect(); long started = System.currentTimeMillis(); while (link.getState() != Link.State.NOT_CONNECTED && link.getState() != Link.State.DISCONNECTING && System.currentTimeMillis() - started < 10000 //wait 10 sec max && !Thread.currentThread().isInterrupted()) { try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } link.disconnect(); } assertTrue(link.getState() == Link.State.NOT_CONNECTED || link.getState() == Link.State.DISCONNECTING, "Failed to disconnect from voice channel in a reasonable amount of time"); }
Example #11
Source File: LavalinkTest.java From Lavalink-Client with MIT License | 6 votes |
private static void ensureConnected(JdaLavalink lavalink, VoiceChannel voiceChannel) { JdaLink link = lavalink.getLink(voiceChannel.getGuild()); link.connect(voiceChannel); long started = System.currentTimeMillis(); while (link.getState() != Link.State.CONNECTED && System.currentTimeMillis() - started < 10000 //wait 10 sec max && !Thread.currentThread().isInterrupted()) { try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } link.connect(voiceChannel); } assertEquals(Link.State.CONNECTED, link.getState(), "Failed to connect to voice channel in a reasonable amount of time"); }
Example #12
Source File: LavalinkTest.java From Lavalink-Client with MIT License | 6 votes |
private static VoiceChannel fetchVoiceChannel(JDA jda, long voiceChannelId) { long started = System.currentTimeMillis(); while (jda.getStatus() != JDA.Status.CONNECTED && System.currentTimeMillis() - started < 10000 //wait 10 sec max && !Thread.currentThread().isInterrupted()) { try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } assertEquals(JDA.Status.CONNECTED, jda.getStatus(), "Failed to connect to Discord in a reasonable amount of time"); VoiceChannel voiceChannel = jda.getVoiceChannelById(voiceChannelId); assertNotNull(voiceChannel, "Configured VoiceChannel not found on the configured Discord bot account"); return voiceChannel; }
Example #13
Source File: JDAVoiceInterceptor.java From Lavalink-Client with MIT License | 6 votes |
@Override public boolean onVoiceStateUpdate(@Nonnull VoiceStateUpdate update) { VoiceChannel channel = update.getChannel(); JdaLink link = lavalink.getLink(update.getGuildId()); if (channel == null) { // Null channel means disconnected if (link.getState() != Link.State.DESTROYED) { link.onDisconnected(); } } else { link.setChannel(channel.getId()); // Change expected channel } return link.getState() == Link.State.CONNECTED; }
Example #14
Source File: WebSocketClient.java From JDA with Apache License 2.0 | 6 votes |
public void queueAudioConnect(VoiceChannel channel) { locked("There was an error queueing the audio connect", () -> { final long guildId = channel.getGuild().getIdLong(); ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) { // starting a whole new connection request = new ConnectionRequest(channel, ConnectionStage.CONNECT); queuedAudioConnections.put(guildId, request); } else if (request.getStage() == ConnectionStage.DISCONNECT) { // if planned to disconnect, we want to reconnect request.setStage(ConnectionStage.RECONNECT); } // in all cases, update to this channel request.setChannel(channel); }); }
Example #15
Source File: AudioManagerImpl.java From JDA with Apache License 2.0 | 6 votes |
@Override public void openAudioConnection(VoiceChannel channel) { Checks.notNull(channel, "Provided VoiceChannel"); // if (!AUDIO_SUPPORTED) // throw new UnsupportedOperationException("Sorry! Audio is disabled due to an internal JDA error! Contact Dev!"); if (!getGuild().equals(channel.getGuild())) throw new IllegalArgumentException("The provided VoiceChannel is not a part of the Guild that this AudioManager handles." + "Please provide a VoiceChannel from the proper Guild"); final Member self = getGuild().getSelfMember(); //if (!self.hasPermission(channel, Permission.VOICE_CONNECT)) // throw new InsufficientPermissionException(Permission.VOICE_CONNECT); //If we are already connected to this VoiceChannel, then do nothing. if (audioConnection != null && channel.equals(audioConnection.getChannel())) return; checkChannel(channel, self); getJDA().getDirectAudioController().connect(channel); if (audioConnection != null) audioConnection.setChannel(channel); }
Example #16
Source File: LavalinkManager.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
public VoiceChannel getConnectedChannel(@Nonnull Guild guild) { // NOTE: never use the local audio manager, since the audio connection may be remote // there is also no reason to look the channel up remotely from lavalink, if we have access to a real guild // object here, since we can use the voice state of ourselves (and lavalink 1.x is buggy in keeping up with the // current voice channel if the bot is moved around in the client) return guild.getSelfMember().getVoiceState().getChannel(); }
Example #17
Source File: AudioManagerImpl.java From JDA with Apache License 2.0 | 5 votes |
protected void updateVoiceState() { VoiceChannel channel = getConnectedChannel(); if (channel != null) { //This is technically equivalent to an audio open/move packet. getJDA().getDirectAudioController().connect(channel); } }
Example #18
Source File: HereCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected boolean doInternal(GuildMessageReceivedEvent message, BotContext context, String content) throws DiscordException { if (message.getMember().getVoiceState() == null || !message.getMember().getVoiceState().inVoiceChannel()) { messageService.onError(message.getChannel(), "discord.command.here.notInChannel"); return fail(message); } PlaybackInstance instance = playerService.get(message.getGuild()); VoiceChannel channel = playerService.connectToChannel(instance, message.getMember()); if (channel != null) { return ok(message, "discord.command.here.connected", channel.getName()); } return fail(message, "discord.command.here.error"); }
Example #19
Source File: GuildAudioListener.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private long countListeners(VoiceChannel channel) { if (channel == null) { return 0; } Member self = channel.getGuild().getSelfMember(); return channel.getMembers().stream() .filter(e -> !self.equals(e)) .count(); }
Example #20
Source File: JdaLink.java From Lavalink-Client with MIT License | 5 votes |
/** * Eventually connect to a channel. Takes care of disconnecting from an existing connection * * @param channel Channel to connect to */ @SuppressWarnings("WeakerAccess") void connect(VoiceChannel channel, boolean checkChannel) { if (!channel.getGuild().equals(getJda().getGuildById(guild))) throw new IllegalArgumentException("The provided VoiceChannel is not a part of the Guild that this AudioManager handles." + "Please provide a VoiceChannel from the proper Guild"); if (channel.getJDA().isUnavailable(channel.getGuild().getIdLong())) throw new GuildUnavailableException("Cannot open an Audio Connection with an unavailable guild. " + "Please wait until this Guild is available to open a connection."); final Member self = channel.getGuild().getSelfMember(); if (!self.hasPermission(channel, Permission.VOICE_CONNECT) && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS)) throw new InsufficientPermissionException(channel, Permission.VOICE_CONNECT); //If we are already connected to this VoiceChannel, then do nothing. if (checkChannel && channel.equals(channel.getGuild().getSelfMember().getVoiceState().getChannel())) return; if (channel.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) { final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set! if (!self.isOwner() && !self.hasPermission(Permission.ADMINISTRATOR)) { if (userLimit > 0 // If there is a userlimit && userLimit <= channel.getMembers().size() // if that userlimit is reached && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS)) // If we don't have voice move others permissions throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS, // then throw exception! "Unable to connect to VoiceChannel due to userlimit! Requires permission VOICE_MOVE_OTHERS to bypass"); } } setState(State.CONNECTING); queueAudioConnect(channel.getIdLong()); }
Example #21
Source File: VoiceActivityListener.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private void stopRecord(VoiceChannel channel, Member member) { GuildVoiceActivityTracker tracker = trackers.getIfPresent(channel.getGuild().getIdLong()); if (tracker == null) { return; } MemberVoiceState state = tracker.remove(channel, member); if (state != null) { rankingService.addVoiceActivity(member, state); } if (tracker.isEmpty()) { trackers.invalidate(channel.getIdLong()); } }
Example #22
Source File: DirectAudioControllerImpl.java From JDA with Apache License 2.0 | 5 votes |
@Override public void connect(@Nonnull VoiceChannel channel) { Checks.notNull(channel, "Voice Channel"); JDAImpl jda = getJDA(); WebSocketClient client = jda.getClient(); client.queueAudioConnect(channel); }
Example #23
Source File: VoiceLinkListener.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private Role getRole(GuildConfig config, VoiceChannel channel) { if (channel == null) { return null; } Guild guild = channel.getGuild(); return config.getVoiceLinks() .stream() .filter(e -> channel.getId().equals(e.getChannelId())) .findFirst() .map(e -> guild.getRoleById(e.getRoleId())) .filter(e -> guild.getSelfMember().canInteract(e)) .orElse(null); }
Example #24
Source File: WebSocketClient.java From JDA with Apache License 2.0 | 5 votes |
public ConnectionRequest updateAudioConnection0(long guildId, VoiceChannel connectedChannel) { //Called by VoiceStateUpdateHandler when we receive a response from discord // about our request to CONNECT or DISCONNECT. // "stage" should never be RECONNECT here thus we don't check for that case ConnectionRequest request = queuedAudioConnections.get(guildId); if (request == null) return null; ConnectionStage requestStage = request.getStage(); if (connectedChannel == null) { //If we got an update that DISCONNECT happened // -> If it was on RECONNECT we now switch to CONNECT // -> If it was on DISCONNECT we can now remove it // -> Otherwise we ignore it switch (requestStage) { case DISCONNECT: return queuedAudioConnections.remove(guildId); case RECONNECT: request.setStage(ConnectionStage.CONNECT); request.setNextAttemptEpoch(System.currentTimeMillis()); default: return null; } } else if (requestStage == ConnectionStage.CONNECT) { //If the removeRequest was related to a channel that isn't the currently queued // request, then don't remove it. if (request.getChannelId() == connectedChannel.getIdLong()) return queuedAudioConnections.remove(guildId); } //If the channel is not the one we are looking for! return null; }
Example #25
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 #26
Source File: VoiceChannelListener.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
private void onJoin(VoiceChannel vc) { GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState(); if (validate(vs)) return; if (!isAlone(vc)) { GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild()); if(gmm == null) return; TrackScheduler scheduler = gmm.getTrackScheduler(); if (scheduler.getCurrentTrack() != null) { if (gmm.isAwaitingDeath()) { TextChannel tc = scheduler.getRequestedTextChannel(); if (tc.canTalk() && vcRatelimiter.process(vc.getGuild().getId())) { tc.sendMessageFormat( scheduler.getLanguage().get("commands.music_general.listener.resumed"), EmoteReference.POPPER ).queue(); } } } gmm.cancelLeave(); gmm.setAwaitingDeath(false); gmm.getLavaLink().getPlayer().setPaused(false); } }
Example #27
Source File: VoiceChannelListener.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
private void onLeave(VoiceChannel vc) { GuildVoiceState vs = vc.getGuild().getSelfMember().getVoiceState(); if (validate(vs)) return; if (isAlone(vc)) { GuildMusicManager gmm = MantaroBot.getInstance().getAudioManager().getMusicManager(vc.getGuild()); if(gmm == null) return; TrackScheduler scheduler = gmm.getTrackScheduler(); if (scheduler != null && scheduler.getCurrentTrack() != null && scheduler.getRequestedTextChannel() != null) { TextChannel tc = scheduler.getRequestedTextChannel(); if (tc.canTalk() && vcRatelimiter.process(vc.getGuild().getId())) { tc.sendMessageFormat(scheduler.getLanguage().get( "commands.music_general.listener.left_alone"), EmoteReference.THINKING, vc.getName() ).queue(m -> m.delete() .queueAfter(30, TimeUnit.SECONDS) ); } } gmm.setAwaitingDeath(true); gmm.scheduleLeave(); gmm.getLavaLink().getPlayer().setPaused(true); } }
Example #28
Source File: Network.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
public void die() { DiscordSRV.debug("Network " + this + " is dying"); VoiceModule.get().getNetworks().remove(this); DiscordSRV.getPlugin().getJda().removeEventListener(this); new HashSet<>(players).forEach(player -> this.disconnect(player, false)); // new set made to prevent concurrent modification VoiceChannel channel = getChannel(); if (channel != null) { channel.getMembers().forEach(VoiceModule::moveToLobby); channel.delete().reason("Lost communication").queue(null, throwable -> DiscordSRV.error("Failed to delete " + channel + ": " + throwable.getMessage()) ); } }
Example #29
Source File: GenericVoiceChannelUpdateEvent.java From JDA with Apache License 2.0 | 5 votes |
public GenericVoiceChannelUpdateEvent( @Nonnull JDA api, long responseNumber, @Nonnull VoiceChannel channel, @Nullable T prev, @Nullable T next, @Nonnull String identifier) { super(api, responseNumber, channel); this.prev = prev; this.next = next; this.identifier = identifier; }
Example #30
Source File: GuildManagerImpl.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override @CheckReturnValue public GuildManagerImpl setAfkChannel(VoiceChannel afkChannel) { Checks.check(afkChannel == null || afkChannel.getGuild().equals(getGuild()), "Channel must be from the same guild"); this.afkChannel = afkChannel == null ? null : afkChannel.getId(); set |= AFK_CHANNEL; return this; }