Fix no-argument !join command.
This commit is contained in:
parent
3f5ed0af08
commit
14492728ab
|
@ -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<VoiceChannel> voiceChannels = guild.getVoiceChannels();
|
||||
Optional<VoiceChannel> 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<Member> 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);
|
||||
|
|
Loading…
Reference in New Issue