Search in sources :

Example 6 with MissingAccessException

use of net.dv8tion.jda.api.exceptions.MissingAccessException in project JDA by DV8FromTheWorld.

the class NewsChannel method follow.

/**
 * Subscribes to the crossposted messages in this channel.
 * <br>This will create a {@link Webhook} of type {@link WebhookType#FOLLOWER FOLLOWER} in the target channel.
 *
 * <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include:
 * <ul>
 *     <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
 *     <br>If the target channel doesn't exist or not visible to the currently logged in account</li>
 *
 *     <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
 *     <br>If the currently logged in account does not have {@link Permission#MANAGE_WEBHOOKS} in the <b>target channel</b></li>
 *
 *     <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MAX_WEBHOOKS MAX_WEBHOOKS}
 *     <br>If the target channel already has reached the maximum capacity for webhooks</li>
 * </ul>
 *
 * @param  targetChannel
 *         The target channel
 *
 * @throws InsufficientPermissionException
 *         If the currently logged in account does not have {@link Permission#MANAGE_WEBHOOKS} in the <b>target channel</b>.
 * @throws IllegalArgumentException
 *         If null is provided
 *
 * @return {@link RestAction}
 *
 * @since  4.2.1
 */
@Nonnull
@CheckReturnValue
default RestAction<Webhook.WebhookReference> follow(@Nonnull TextChannel targetChannel) {
    Checks.notNull(targetChannel, "Target Channel");
    Member selfMember = targetChannel.getGuild().getSelfMember();
    if (!selfMember.hasAccess(targetChannel))
        throw new MissingAccessException(targetChannel, Permission.VIEW_CHANNEL);
    if (!selfMember.hasPermission(targetChannel, Permission.MANAGE_WEBHOOKS))
        throw new InsufficientPermissionException(targetChannel, Permission.MANAGE_WEBHOOKS);
    return follow(targetChannel.getId());
}
Also used : InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) MissingAccessException(net.dv8tion.jda.api.exceptions.MissingAccessException) CheckReturnValue(javax.annotation.CheckReturnValue) Nonnull(javax.annotation.Nonnull)

Example 7 with MissingAccessException

use of net.dv8tion.jda.api.exceptions.MissingAccessException in project JDA by DV8FromTheWorld.

the class PermOverrideManagerImpl method checkPermissions.

@Override
protected boolean checkPermissions() {
    Member selfMember = getGuild().getSelfMember();
    IPermissionContainer channel = getChannel();
    if (!selfMember.hasPermission(channel, Permission.VIEW_CHANNEL))
        throw new MissingAccessException(channel, Permission.VIEW_CHANNEL);
    if (!selfMember.hasAccess(channel))
        throw new MissingAccessException(channel, Permission.VOICE_CONNECT);
    if (!selfMember.hasPermission(channel, Permission.MANAGE_PERMISSIONS))
        throw new InsufficientPermissionException(channel, Permission.MANAGE_PERMISSIONS);
    return super.checkPermissions();
}
Also used : InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) MissingAccessException(net.dv8tion.jda.api.exceptions.MissingAccessException) Member(net.dv8tion.jda.api.entities.Member) IPermissionContainer(net.dv8tion.jda.api.entities.IPermissionContainer) PermissionOverride(net.dv8tion.jda.api.entities.PermissionOverride)

Example 8 with MissingAccessException

use of net.dv8tion.jda.api.exceptions.MissingAccessException in project JDA by DV8FromTheWorld.

the class WebhookManagerImpl method checkPermissions.

@Override
protected boolean checkPermissions() {
    Member selfMember = getGuild().getSelfMember();
    BaseGuildMessageChannel channel = getChannel();
    if (!selfMember.hasAccess(channel))
        throw new MissingAccessException(channel, Permission.VIEW_CHANNEL);
    if (!selfMember.hasPermission(channel, Permission.MANAGE_WEBHOOKS))
        throw new InsufficientPermissionException(channel, Permission.MANAGE_WEBHOOKS);
    return super.checkPermissions();
}
Also used : InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) MissingAccessException(net.dv8tion.jda.api.exceptions.MissingAccessException)

Aggregations

MissingAccessException (net.dv8tion.jda.api.exceptions.MissingAccessException)8 InsufficientPermissionException (net.dv8tion.jda.api.exceptions.InsufficientPermissionException)7 Nonnull (javax.annotation.Nonnull)3 CheckReturnValue (javax.annotation.CheckReturnValue)2 IPermissionContainer (net.dv8tion.jda.api.entities.IPermissionContainer)1 Member (net.dv8tion.jda.api.entities.Member)1 PermissionOverride (net.dv8tion.jda.api.entities.PermissionOverride)1 RestActionImpl (net.dv8tion.jda.internal.requests.RestActionImpl)1 Route (net.dv8tion.jda.internal.requests.Route)1