Discord JDA - getMembers() 不工作,returns 0 无论如何
Discord JDA - getMembers() not working, returns 0 anyway
我的代码是这样的:
public void onGuildVoiceJoin(GuildVoiceJoinEvent event) {
String channelId = event.getChannelJoined().getId();
if (channelId.equals("904375329764814870")) {
Member member = event.getMember();
String memberName = event.getMember().getEffectiveName();
Category category = event.getGuild().getCategoryById("904364634507706468");
event.getGuild().createVoiceChannel("Coaching " + memberName).setParent(category).complete();
List<VoiceChannel> channelList = event.getGuild().getVoiceChannelsByName("Coaching " + memberName, true);
VoiceChannel channel = channelList.get(0);
event.getGuild().moveVoiceMember(member, channel).queue();
while (true){
event.getGuild().getTextChannelById("904364671467929610").sendMessage(
"Number of people currently on the channel : " + channel.getMembers().size()
).queue();
wait(3000);
}
我的目标是获取当前频道内的人数。
我认为 getMembers() 方法是个好方法,但它不起作用
我使用无限 while 查看 channel.getMembers().size() 是否在我 join/leave 通道时发生变化,但它仍然是 return 0.
我该如何解决这个问题?并获得频道内的正确人数 return.
The final goal of my code is to delete the channel when he's empty of user
这可以通过检查 GuildVoiceUpdateEvent:
中的成员数来实现
public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) {
if (channel.getName().startsWith("Coaching ")) { // check if name matches the desired name
if (channel.getMembers().isEmpty()) { // check if channel is empty
channel.delete().queue(); // delete channel
}
}
}
我的代码是这样的:
public void onGuildVoiceJoin(GuildVoiceJoinEvent event) {
String channelId = event.getChannelJoined().getId();
if (channelId.equals("904375329764814870")) {
Member member = event.getMember();
String memberName = event.getMember().getEffectiveName();
Category category = event.getGuild().getCategoryById("904364634507706468");
event.getGuild().createVoiceChannel("Coaching " + memberName).setParent(category).complete();
List<VoiceChannel> channelList = event.getGuild().getVoiceChannelsByName("Coaching " + memberName, true);
VoiceChannel channel = channelList.get(0);
event.getGuild().moveVoiceMember(member, channel).queue();
while (true){
event.getGuild().getTextChannelById("904364671467929610").sendMessage(
"Number of people currently on the channel : " + channel.getMembers().size()
).queue();
wait(3000);
}
我的目标是获取当前频道内的人数。
我认为 getMembers() 方法是个好方法,但它不起作用
我使用无限 while 查看 channel.getMembers().size() 是否在我 join/leave 通道时发生变化,但它仍然是 return 0.
我该如何解决这个问题?并获得频道内的正确人数 return.
The final goal of my code is to delete the channel when he's empty of user
这可以通过检查 GuildVoiceUpdateEvent:
中的成员数来实现public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) {
if (channel.getName().startsWith("Coaching ")) { // check if name matches the desired name
if (channel.getMembers().isEmpty()) { // check if channel is empty
channel.delete().queue(); // delete channel
}
}
}