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;
|
VoiceChannel channel = null;
|
||||||
if (args.isEmpty() || args.get(0).isBlank())
|
if (args.isEmpty() || args.get(0).isBlank())
|
||||||
{
|
{
|
||||||
GuildVoiceState voiceState = event.getMember().getVoiceState();
|
final Member member = event.getMessage().getMember();
|
||||||
if (voiceState != null && voiceState.inVoiceChannel())
|
if (member != null)
|
||||||
channel = voiceState.getChannel();
|
{
|
||||||
else
|
GuildVoiceState voiceState = member.getVoiceState();
|
||||||
|
if (voiceState != null && voiceState.inVoiceChannel())
|
||||||
|
channel = voiceState.getChannel();
|
||||||
|
}
|
||||||
|
if (channel == null)
|
||||||
{
|
{
|
||||||
Guild guild = event.getMessage().getGuild();
|
Guild guild = event.getMessage().getGuild();
|
||||||
List<VoiceChannel> voiceChannels = guild.getVoiceChannels();
|
List<VoiceChannel> voiceChannels = guild.getVoiceChannels();
|
||||||
Optional<VoiceChannel> findFirst = voiceChannels.stream().filter((t) -> !t.getMembers().isEmpty()).findFirst();
|
System.out.println("Finding channel to join...");
|
||||||
channel = findFirst.orElseThrow(() -> new RuntimeException("Cannot find any voice channels with people in!"));
|
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
|
} else
|
||||||
{
|
{
|
||||||
String arg0 = args.get(0);
|
String arg0 = args.get(0);
|
||||||
|
|
Loading…
Reference in New Issue