All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dv8tion.jda.api.entities.channel.concrete.NewsChannel Maven / Gradle / Ivy

Go to download

Java wrapper for the popular chat & VOIP service: Discord https://discord.com

There is a newer version: 5.1.0
Show newest version
/*
 * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.dv8tion.jda.api.entities.channel.concrete;

import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.exceptions.MissingAccessException;
import net.dv8tion.jda.api.managers.channel.concrete.NewsChannelManager;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.Route;
import net.dv8tion.jda.api.requests.restaction.ChannelAction;
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.utils.Checks;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

/**
 * Represents {@link net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel} that are News Channels.
 *
 * 

The Discord client may refer to these as Announcement Channels. * *

Members can subscribe channels in their own guilds to receive messages crossposted from this channel. * This is referred to as following this channel. * *

Messages sent in this channel can be crossposted, at which point they will be sent (via webhook) to all subscribed channels. * * @see Message#getFlags() * @see net.dv8tion.jda.api.entities.Message.MessageFlag#CROSSPOSTED */ public interface NewsChannel extends StandardGuildMessageChannel { /** * Subscribes to the crossposted messages in this channel. *
This will create a {@link Webhook} of type {@link WebhookType#FOLLOWER FOLLOWER} in the target channel. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL} *
    If the target channel doesn't exist or is not visible to the currently logged in account
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    If the currently logged in account does not have {@link Permission#MANAGE_WEBHOOKS} in the target channel
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MAX_WEBHOOKS MAX_WEBHOOKS} *
    If the target channel already has reached the maximum capacity for webhooks
  • *
* * @param targetChannelId * The target channel id * * @throws IllegalArgumentException * If null is provided * * @return {@link RestAction} * * @since 4.2.1 */ @Nonnull @CheckReturnValue RestAction follow(@Nonnull String targetChannelId); /** * Subscribes to the crossposted messages in this channel. *
This will create a {@link Webhook} of type {@link WebhookType#FOLLOWER FOLLOWER} in the target channel. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL} *
    If the target channel doesn't exist or not visible to the currently logged in account
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    If the currently logged in account does not have {@link Permission#MANAGE_WEBHOOKS} in the target channel
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MAX_WEBHOOKS MAX_WEBHOOKS} *
    If the target channel already has reached the maximum capacity for webhooks
  • *
* * @param targetChannelId * The target channel id * * @return {@link RestAction} * * @since 4.2.1 */ @Nonnull @CheckReturnValue default RestAction follow(long targetChannelId) { return follow(Long.toUnsignedString(targetChannelId)); } /** * Subscribes to the crossposted messages in this channel. *
This will create a {@link Webhook} of type {@link WebhookType#FOLLOWER FOLLOWER} in the target channel. * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL} *
    If the target channel doesn't exist or not visible to the currently logged in account
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    If the currently logged in account does not have {@link Permission#MANAGE_WEBHOOKS} in the target channel
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MAX_WEBHOOKS MAX_WEBHOOKS} *
    If the target channel already has reached the maximum capacity for webhooks
  • *
* * @param targetChannel * The target channel * * @throws MissingAccessException * If the currently logged in account does not have {@link Member#hasAccess(net.dv8tion.jda.api.entities.channel.middleman.GuildChannel) access} in the target channel. * @throws InsufficientPermissionException * If the currently logged in account does not have {@link Permission#MANAGE_WEBHOOKS} in the target channel. * @throws IllegalArgumentException * If null is provided * * @return {@link RestAction} * * @since 4.2.1 */ @Nonnull @CheckReturnValue default RestAction follow(@Nonnull TextChannel targetChannel) { Checks.notNull(targetChannel, "Target Channel"); Member selfMember = targetChannel.getGuild().getSelfMember(); Checks.checkAccess(selfMember, targetChannel); if (!selfMember.hasPermission(targetChannel, Permission.MANAGE_WEBHOOKS)) throw new InsufficientPermissionException(targetChannel, Permission.MANAGE_WEBHOOKS); return follow(targetChannel.getId()); } /** * Attempts to crosspost the provided message. * *

The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#ALREADY_CROSSPOSTED ALREADY_CROSSPOSTED} *
    The target message has already been crossposted.
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS} *
    The request was attempted after the account lost access to the * {@link net.dv8tion.jda.api.entities.Guild Guild} * typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} * was revoked in the {@link TextChannel TextChannel}
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    The request was attempted after the account lost * {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE} in the TextChannel.
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE} *
    The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or * the message it referred to has already been deleted.
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL} *
    The request was attempted after the channel was deleted.
  • *
* * @param messageId * The messageId to crosspost * * @throws java.lang.IllegalArgumentException * If provided {@code messageId} is {@code null} or empty. * @throws MissingAccessException * If the currently logged in account does not have {@link Member#hasAccess(net.dv8tion.jda.api.entities.channel.middleman.GuildChannel) access} in this channel. * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the currently logged in account does not have * {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} in this channel. * * @return {@link net.dv8tion.jda.api.requests.RestAction} - Type: {@link Message} * * @since 4.2.1 */ @Nonnull @CheckReturnValue default RestAction crosspostMessageById(@Nonnull String messageId) { Checks.isSnowflake(messageId); Checks.checkAccess(getGuild().getSelfMember(), this); Route.CompiledRoute route = Route.Messages.CROSSPOST_MESSAGE.compile(getId(), messageId); return new RestActionImpl<>(getJDA(), route, (response, request) -> request.getJDA().getEntityBuilder().createMessageWithChannel(response.getObject(), this, false)); } /** * Attempts to crosspost the provided message. * *

The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible: *

    *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#ALREADY_CROSSPOSTED ALREADY_CROSSPOSTED} *
    The target message has already been crossposted.
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS} *
    The request was attempted after the account lost access to the * {@link net.dv8tion.jda.api.entities.Guild Guild} * typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} * was revoked in the {@link TextChannel TextChannel}
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS} *
    The request was attempted after the account lost * {@link net.dv8tion.jda.api.Permission#MESSAGE_MANAGE Permission.MESSAGE_MANAGE} in the TextChannel.
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE} *
    The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or * the message it referred to has already been deleted.
  • * *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL} *
    The request was attempted after the channel was deleted.
  • *
* * @param messageId * The messageId to crosspost * * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException * If the currently logged in account does not have * {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} in this channel. * * @return {@link net.dv8tion.jda.api.requests.RestAction} - Type: {@link Message} * * @since 4.2.1 */ @Nonnull @CheckReturnValue default RestAction crosspostMessageById(long messageId) { return crosspostMessageById(Long.toUnsignedString(messageId)); } @Nonnull @Override ChannelAction createCopy(@Nonnull Guild guild); @Nonnull @Override default ChannelAction createCopy() { return createCopy(getGuild()); } @Nonnull @Override NewsChannelManager getManager(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy