Skip to content

Commit

Permalink
Make Guild#moveVoiceMember support AudioChannel instead (#1928)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlnrDev committed Dec 2, 2021
1 parent 2fe9609 commit 0e726a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
30 changes: 15 additions & 15 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Expand Up @@ -3790,9 +3790,9 @@ default Task<List<Member>> retrieveMembersByIds(boolean includePresence, @Nonnul
/* From GuildController */

/**
* Used to move a {@link net.dv8tion.jda.api.entities.Member Member} from one {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}
* to another {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}.
* <br>As a note, you cannot move a Member that isn't already in a VoiceChannel. Also they must be in a VoiceChannel
* Used to move a {@link net.dv8tion.jda.api.entities.Member Member} from one {@link net.dv8tion.jda.api.entities.AudioChannel AudioChannel}
* to another {@link net.dv8tion.jda.api.entities.AudioChannel AudioChannel}.
* <br>As a note, you cannot move a Member that isn't already in a AudioChannel. Also they must be in a AudioChannel
* in the same Guild as the one that you are moving them to.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
Expand All @@ -3813,35 +3813,35 @@ default Task<List<Member>> retrieveMembersByIds(boolean includePresence, @Nonnul
*
* @param member
* The {@link net.dv8tion.jda.api.entities.Member Member} that you are moving.
* @param voiceChannel
* The destination {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel} to which the member is being
* @param audioChannel
* The destination {@link net.dv8tion.jda.api.entities.AudioChannel AudioChannel} to which the member is being
* moved to. Or null to perform a voice kick.
*
* @throws IllegalStateException
* If the Member isn't currently in a VoiceChannel in this Guild, or {@link net.dv8tion.jda.api.utils.cache.CacheFlag#VOICE_STATE} is disabled.
* If the Member isn't currently in a AudioChannel in this Guild, or {@link net.dv8tion.jda.api.utils.cache.CacheFlag#VOICE_STATE} is disabled.
* @throws IllegalArgumentException
* <ul>
* <li>If the provided member is {@code null}</li>
* <li>If the provided Member isn't part of this {@link net.dv8tion.jda.api.entities.Guild Guild}</li>
* <li>If the provided VoiceChannel isn't part of this {@link net.dv8tion.jda.api.entities.Guild Guild}</li>
* <li>If the provided AudioChannel isn't part of this {@link net.dv8tion.jda.api.entities.Guild Guild}</li>
* </ul>
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* <ul>
* <li>If this account doesn't have {@link net.dv8tion.jda.api.Permission#VOICE_MOVE_OTHERS}
* in the VoiceChannel that the Member is currently in.</li>
* in the AudioChannel that the Member is currently in.</li>
* <li>If this account <b>AND</b> the Member being moved don't have
* {@link net.dv8tion.jda.api.Permission#VOICE_CONNECT} for the destination VoiceChannel.</li>
* {@link net.dv8tion.jda.api.Permission#VOICE_CONNECT} for the destination AudioChannel.</li>
* </ul>
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction}
*/
@Nonnull
@CheckReturnValue
RestAction<Void> moveVoiceMember(@Nonnull Member member, @Nullable VoiceChannel voiceChannel);
RestAction<Void> moveVoiceMember(@Nonnull Member member, @Nullable AudioChannel audioChannel);

/**
* Used to kick a {@link net.dv8tion.jda.api.entities.Member Member} from a {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}.
* <br>As a note, you cannot kick a Member that isn't already in a VoiceChannel. Also they must be in a VoiceChannel
* Used to kick a {@link net.dv8tion.jda.api.entities.Member Member} from a {@link net.dv8tion.jda.api.entities.AudioChannel AudioChannel}.
* <br>As a note, you cannot kick a Member that isn't already in a AudioChannel. Also they must be in a AudioChannel
* in the same Guild.
*
* <p>Equivalent to {@code moveVoiceMember(member, null)}.
Expand All @@ -3863,16 +3863,16 @@ default Task<List<Member>> retrieveMembersByIds(boolean includePresence, @Nonnul
* The {@link net.dv8tion.jda.api.entities.Member Member} that you are moving.
*
* @throws IllegalStateException
* If the Member isn't currently in a VoiceChannel in this Guild, or {@link net.dv8tion.jda.api.utils.cache.CacheFlag#VOICE_STATE} is disabled.
* If the Member isn't currently in a AudioChannel in this Guild, or {@link net.dv8tion.jda.api.utils.cache.CacheFlag#VOICE_STATE} is disabled.
* @throws IllegalArgumentException
* <ul>
* <li>If any of the provided arguments is {@code null}</li>
* <li>If the provided Member isn't part of this {@link net.dv8tion.jda.api.entities.Guild Guild}</li>
* <li>If the provided VoiceChannel isn't part of this {@link net.dv8tion.jda.api.entities.Guild Guild}</li>
* <li>If the provided AudioChannel isn't part of this {@link net.dv8tion.jda.api.entities.Guild Guild}</li>
* </ul>
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If this account doesn't have {@link net.dv8tion.jda.api.Permission#VOICE_MOVE_OTHERS}
* in the VoiceChannel that the Member is currently in.
* in the AudioChannel that the Member is currently in.
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction}
*/
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java
Expand Up @@ -1215,31 +1215,31 @@ public RestAction<Template> createTemplate(@Nonnull String name, @Nullable Strin

@Nonnull
@Override
public RestAction<Void> moveVoiceMember(@Nonnull Member member, @Nullable VoiceChannel voiceChannel)
public RestAction<Void> moveVoiceMember(@Nonnull Member member, @Nullable AudioChannel audioChannel)
{
Checks.notNull(member, "Member");
checkGuild(member.getGuild(), "Member");
if (voiceChannel != null)
checkGuild(voiceChannel.getGuild(), "VoiceChannel");
if (audioChannel != null)
checkGuild(audioChannel.getGuild(), "AudioChannel");

GuildVoiceState vState = member.getVoiceState();
if (vState == null)
throw new IllegalStateException("Cannot move a Member with disabled CacheFlag.VOICE_STATE");
AudioChannel channel = vState.getChannel();
if (channel == null)
throw new IllegalStateException("You cannot move a Member who isn't in a VoiceChannel!");
throw new IllegalStateException("You cannot move a Member who isn't in an AudioChannel!");

if (!PermissionUtil.checkPermission((IPermissionContainer) channel, getSelfMember(), Permission.VOICE_MOVE_OTHERS))
throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS, "This account does not have Permission to MOVE_OTHERS out of the channel that the Member is currently in.");

if (voiceChannel != null
&& !PermissionUtil.checkPermission(voiceChannel, getSelfMember(), Permission.VOICE_CONNECT)
&& !PermissionUtil.checkPermission(voiceChannel, member, Permission.VOICE_CONNECT))
throw new InsufficientPermissionException(voiceChannel, Permission.VOICE_CONNECT,
if (audioChannel != null
&& !getSelfMember().hasPermission(audioChannel, Permission.VOICE_CONNECT)
&& !member.hasPermission(audioChannel, Permission.VOICE_CONNECT))
throw new InsufficientPermissionException(audioChannel, Permission.VOICE_CONNECT,
"Neither this account nor the Member that is attempting to be moved have the VOICE_CONNECT permission " +
"for the destination VoiceChannel, so the move cannot be done.");
"for the destination AudioChannel, so the move cannot be done.");

DataObject body = DataObject.empty().put("channel_id", voiceChannel == null ? null : voiceChannel.getId());
DataObject body = DataObject.empty().put("channel_id", audioChannel == null ? null : audioChannel.getId());
Route.CompiledRoute route = Route.Guilds.MODIFY_MEMBER.compile(getId(), member.getUser().getId());
return new RestActionImpl<>(getJDA(), route, body);
}
Expand Down

0 comments on commit 0e726a8

Please sign in to comment.