Skip to content

Commit 5141a94

Browse files
authored
Check mute/deafen permissions using the channel (#2781)
1 parent 5ec2d8e commit 5141a94

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/main/java/net/dv8tion/jda/api/entities/Guild.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,7 +3985,8 @@ default AuditableRestAction<Void> timeoutFor(@Nonnull UserSnowflake user, @Nonnu
39853985
* Whether this {@link net.dv8tion.jda.api.entities.Member Member} should be deafened or undeafened.
39863986
*
39873987
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
3988-
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#VOICE_DEAF_OTHERS} permission.
3988+
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#VOICE_DEAF_OTHERS} permission
3989+
* in the given channel.
39893990
* @throws IllegalArgumentException
39903991
* If the provided user is null.
39913992
* @throws java.lang.IllegalStateException
@@ -4024,7 +4025,8 @@ default AuditableRestAction<Void> timeoutFor(@Nonnull UserSnowflake user, @Nonnu
40244025
* Whether this {@link net.dv8tion.jda.api.entities.Member Member} should be muted or unmuted.
40254026
*
40264027
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
4027-
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#VOICE_DEAF_OTHERS} permission.
4028+
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#VOICE_DEAF_OTHERS} permission
4029+
* in the given channel.
40284030
* @throws java.lang.IllegalArgumentException
40294031
* If the provided user is null.
40304032
* @throws java.lang.IllegalStateException

src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import net.dv8tion.jda.api.entities.channel.concrete.*;
3333
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
3434
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
35+
import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion;
3536
import net.dv8tion.jda.api.entities.channel.unions.DefaultGuildChannelUnion;
3637
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
3738
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
@@ -64,6 +65,7 @@
6465
import net.dv8tion.jda.api.utils.data.DataObject;
6566
import net.dv8tion.jda.internal.JDAImpl;
6667
import net.dv8tion.jda.internal.entities.automod.AutoModRuleImpl;
68+
import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin;
6769
import net.dv8tion.jda.internal.handle.EventCache;
6870
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
6971
import net.dv8tion.jda.internal.interactions.command.CommandImpl;
@@ -1641,18 +1643,19 @@ private AuditableRestAction<Void> timeoutUntilById0(@Nonnull String userId, @Nul
16411643
public AuditableRestAction<Void> deafen(@Nonnull UserSnowflake user, boolean deafen)
16421644
{
16431645
Checks.notNull(user, "User");
1644-
checkPermission(Permission.VOICE_DEAF_OTHERS);
16451646

16461647
Member member = resolveMember(user);
16471648
if (member != null)
16481649
{
16491650
GuildVoiceState voiceState = member.getVoiceState();
16501651
if (voiceState != null)
16511652
{
1652-
if (voiceState.getChannel() == null)
1653+
final AudioChannelUnion channel = voiceState.getChannel();
1654+
if (channel == null)
16531655
throw new IllegalStateException("Can only deafen members who are currently in a voice channel");
16541656
if (voiceState.isGuildDeafened() == deafen)
16551657
return new CompletedRestAction<>(getJDA(), null);
1658+
((GuildChannelMixin<?>) channel).checkPermission(Permission.VOICE_DEAF_OTHERS);
16561659
}
16571660
}
16581661

@@ -1666,18 +1669,19 @@ public AuditableRestAction<Void> deafen(@Nonnull UserSnowflake user, boolean dea
16661669
public AuditableRestAction<Void> mute(@Nonnull UserSnowflake user, boolean mute)
16671670
{
16681671
Checks.notNull(user, "User");
1669-
checkPermission(Permission.VOICE_MUTE_OTHERS);
16701672

16711673
Member member = resolveMember(user);
16721674
if (member != null)
16731675
{
16741676
GuildVoiceState voiceState = member.getVoiceState();
16751677
if (voiceState != null)
16761678
{
1677-
if (voiceState.getChannel() == null)
1679+
final AudioChannelUnion channel = voiceState.getChannel();
1680+
if (channel == null)
16781681
throw new IllegalStateException("Can only mute members who are currently in a voice channel");
16791682
if (voiceState.isGuildMuted() == mute && (mute || !voiceState.isSuppressed()))
16801683
return new CompletedRestAction<>(getJDA(), null);
1684+
((GuildChannelMixin<?>) channel).checkPermission(Permission.VOICE_MUTE_OTHERS);
16811685
}
16821686
}
16831687

0 commit comments

Comments
 (0)