I must set denied the right to connect to a voice channel for two users selected in the EntitySelectMenu. For this, I am trying to use this code:
In EntitySelectInteraction:
for (int i = 0; i < 2; i++) {
event.getMember().getVoiceState().getChannel().asVoiceChannel().getManager()
.putMemberPermissionOverride(Long.parseLong(event.getMentions().getMembers().get(i).getId()), null, EnumSet
.of(Permission.VOICE_CONNECT)).complete();
}
But this code changes the rights in the channel only for the user who was selected second and simply ignores the first one. What could be causing this? How to avoid it? I would be grateful for any help.
You should re-use the same manager to add multiple overrides in a single request:
VoiceChannelManager manager = event.getMember().getVoiceState().getChannel().asVoiceChannel().getManager();
EnumSet<Permission> denied = EnumSet.of(Permission.VOICE_CONNECT);
for (Member member : event.getMentions().getMembers()) {
manager.putPermissionOverride(member, null, denied);
}
manager.queue();