Java Code Examples for net.dv8tion.jda.api.Permission#VOICE_CONNECT

The following examples show how to use net.dv8tion.jda.api.Permission#VOICE_CONNECT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AudioManagerImpl.java    From JDA with Apache License 2.0 6 votes vote down vote up
private void checkChannel(VoiceChannel channel, Member self)
{
    EnumSet<Permission> perms = Permission.getPermissions(PermissionUtil.getEffectivePermission(channel, self));
    if (!perms.contains(Permission.VOICE_CONNECT))
        throw new InsufficientPermissionException(channel, Permission.VOICE_CONNECT);
    final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set!
    if (userLimit > 0 && !perms.contains(Permission.ADMINISTRATOR))
    {
        // Check if we can actually join this channel
        // - If there is a userlimit
        // - If that userlimit is reached
        // - If we don't have voice move others permissions
        // VOICE_MOVE_OTHERS allows access because you would be able to move people out to
        // open up a slot anyway
        if (userLimit <= channel.getMembers().size()
            && !perms.contains(Permission.VOICE_MOVE_OTHERS))
        {
            throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS,
                "Unable to connect to VoiceChannel due to userlimit! Requires permission VOICE_MOVE_OTHERS to bypass");
        }
    }
}
 
Example 2
Source File: JdaLink.java    From Lavalink-Client with MIT License 5 votes vote down vote up
/**
 * Eventually connect to a channel. Takes care of disconnecting from an existing connection
 *
 * @param channel Channel to connect to
 */
@SuppressWarnings("WeakerAccess")
void connect(VoiceChannel channel, boolean checkChannel) {
    if (!channel.getGuild().equals(getJda().getGuildById(guild)))
        throw new IllegalArgumentException("The provided VoiceChannel is not a part of the Guild that this AudioManager handles." +
                "Please provide a VoiceChannel from the proper Guild");
    if (channel.getJDA().isUnavailable(channel.getGuild().getIdLong()))
        throw new GuildUnavailableException("Cannot open an Audio Connection with an unavailable guild. " +
                "Please wait until this Guild is available to open a connection.");
    final Member self = channel.getGuild().getSelfMember();
    if (!self.hasPermission(channel, Permission.VOICE_CONNECT) && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS))
        throw new InsufficientPermissionException(channel, Permission.VOICE_CONNECT);

    //If we are already connected to this VoiceChannel, then do nothing.
    if (checkChannel && channel.equals(channel.getGuild().getSelfMember().getVoiceState().getChannel()))
        return;

    if (channel.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
        final int userLimit = channel.getUserLimit(); // userLimit is 0 if no limit is set!
        if (!self.isOwner() && !self.hasPermission(Permission.ADMINISTRATOR)) {
            if (userLimit > 0                                                      // If there is a userlimit
                    && userLimit <= channel.getMembers().size()                    // if that userlimit is reached
                    && !self.hasPermission(channel, Permission.VOICE_MOVE_OTHERS)) // If we don't have voice move others permissions
                throw new InsufficientPermissionException(channel, Permission.VOICE_MOVE_OTHERS, // then throw exception!
                        "Unable to connect to VoiceChannel due to userlimit! Requires permission VOICE_MOVE_OTHERS to bypass");
        }
    }

    setState(State.CONNECTING);
    queueAudioConnect(channel.getIdLong());
}
 
Example 3
Source File: GuildImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public RestAction<Void> moveVoiceMember(@Nonnull Member member, @Nullable VoiceChannel voiceChannel)
{
    Checks.notNull(member, "Member");
    checkGuild(member.getGuild(), "Member");
    if (voiceChannel != null)
        checkGuild(voiceChannel.getGuild(), "VoiceChannel");

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

    if (!PermissionUtil.checkPermission(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,
                                                  "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.");

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