From 14492728ab6babb3dec68c086aa7481b7213ef0a Mon Sep 17 00:00:00 2001 From: Nekojimi Date: Wed, 18 May 2022 20:43:40 +0100 Subject: [PATCH] Fix no-argument !join command. --- .../nekojimi/chords/commands/JoinCommand.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/moe/nekojimi/chords/commands/JoinCommand.java b/src/main/java/moe/nekojimi/chords/commands/JoinCommand.java index c22e161..a6af543 100644 --- a/src/main/java/moe/nekojimi/chords/commands/JoinCommand.java +++ b/src/main/java/moe/nekojimi/chords/commands/JoinCommand.java @@ -26,16 +26,28 @@ public class JoinCommand extends Command VoiceChannel channel = null; if (args.isEmpty() || args.get(0).isBlank()) { - GuildVoiceState voiceState = event.getMember().getVoiceState(); - if (voiceState != null && voiceState.inVoiceChannel()) - channel = voiceState.getChannel(); - else + final Member member = event.getMessage().getMember(); + if (member != null) + { + GuildVoiceState voiceState = member.getVoiceState(); + if (voiceState != null && voiceState.inVoiceChannel()) + channel = voiceState.getChannel(); + } + if (channel == null) { Guild guild = event.getMessage().getGuild(); List voiceChannels = guild.getVoiceChannels(); - Optional findFirst = voiceChannels.stream().filter((t) -> !t.getMembers().isEmpty()).findFirst(); - channel = findFirst.orElseThrow(() -> new RuntimeException("Cannot find any voice channels with people in!")); + System.out.println("Finding channel to join..."); + for (VoiceChannel voiceChannel : voiceChannels) + { + List members = voiceChannel.getMembers(); + if (!members.isEmpty()) + channel = voiceChannel; + System.out.println("\t" + voiceChannel.getName() + " " + members.size()); + } } + if (channel == null) + throw new RuntimeException("Cannot find any voice channels with people in!"); } else { String arg0 = args.get(0);