diff --git a/src/main/java/net/dv8tion/jda/api/entities/Guild.java b/src/main/java/net/dv8tion/jda/api/entities/Guild.java index ab252daeed..7dea7c4268 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/Guild.java +++ b/src/main/java/net/dv8tion/jda/api/entities/Guild.java @@ -3985,7 +3985,8 @@ default AuditableRestAction timeoutFor(@Nonnull UserSnowflake user, @Nonnu * Whether this {@link net.dv8tion.jda.api.entities.Member Member} should be deafened or undeafened. * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException - * If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#VOICE_DEAF_OTHERS} permission. + * If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#VOICE_DEAF_OTHERS} permission + * in the given channel. * @throws IllegalArgumentException * If the provided user is null. * @throws java.lang.IllegalStateException @@ -4024,7 +4025,8 @@ default AuditableRestAction timeoutFor(@Nonnull UserSnowflake user, @Nonnu * Whether this {@link net.dv8tion.jda.api.entities.Member Member} should be muted or unmuted. * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException - * If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#VOICE_DEAF_OTHERS} permission. + * If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#VOICE_DEAF_OTHERS} permission + * in the given channel. * @throws java.lang.IllegalArgumentException * If the provided user is null. * @throws java.lang.IllegalStateException diff --git a/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java index 511ae41d7d..d8228481e0 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java @@ -32,6 +32,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.*; import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; +import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion; import net.dv8tion.jda.api.entities.channel.unions.DefaultGuildChannelUnion; import net.dv8tion.jda.api.entities.emoji.CustomEmoji; import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji; @@ -64,6 +65,7 @@ import net.dv8tion.jda.api.utils.data.DataObject; import net.dv8tion.jda.internal.JDAImpl; import net.dv8tion.jda.internal.entities.automod.AutoModRuleImpl; +import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin; import net.dv8tion.jda.internal.handle.EventCache; import net.dv8tion.jda.internal.interactions.CommandDataImpl; import net.dv8tion.jda.internal.interactions.command.CommandImpl; @@ -1641,7 +1643,6 @@ private AuditableRestAction timeoutUntilById0(@Nonnull String userId, @Nul public AuditableRestAction deafen(@Nonnull UserSnowflake user, boolean deafen) { Checks.notNull(user, "User"); - checkPermission(Permission.VOICE_DEAF_OTHERS); Member member = resolveMember(user); if (member != null) @@ -1649,10 +1650,12 @@ public AuditableRestAction deafen(@Nonnull UserSnowflake user, boolean dea GuildVoiceState voiceState = member.getVoiceState(); if (voiceState != null) { - if (voiceState.getChannel() == null) + final AudioChannelUnion channel = voiceState.getChannel(); + if (channel == null) throw new IllegalStateException("Can only deafen members who are currently in a voice channel"); if (voiceState.isGuildDeafened() == deafen) return new CompletedRestAction<>(getJDA(), null); + ((GuildChannelMixin) channel).checkPermission(Permission.VOICE_DEAF_OTHERS); } } @@ -1666,7 +1669,6 @@ public AuditableRestAction deafen(@Nonnull UserSnowflake user, boolean dea public AuditableRestAction mute(@Nonnull UserSnowflake user, boolean mute) { Checks.notNull(user, "User"); - checkPermission(Permission.VOICE_MUTE_OTHERS); Member member = resolveMember(user); if (member != null) @@ -1674,10 +1676,12 @@ public AuditableRestAction mute(@Nonnull UserSnowflake user, boolean mute) GuildVoiceState voiceState = member.getVoiceState(); if (voiceState != null) { - if (voiceState.getChannel() == null) + final AudioChannelUnion channel = voiceState.getChannel(); + if (channel == null) throw new IllegalStateException("Can only mute members who are currently in a voice channel"); if (voiceState.isGuildMuted() == mute && (mute || !voiceState.isSuppressed())) return new CompletedRestAction<>(getJDA(), null); + ((GuildChannelMixin) channel).checkPermission(Permission.VOICE_MUTE_OTHERS); } }