net.dv8tion.jda.api.entities.NewsChannel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JDA Show documentation
Show all versions of JDA Show documentation
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
package net.dv8tion.jda.api.entities;
import net.dv8tion.jda.api.Permission;
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.restaction.ChannelAction;
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.requests.Route;
import net.dv8tion.jda.internal.utils.Checks;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
/**
* Represents {@link BaseGuildMessageChannel} 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 BaseGuildMessageChannel
{
/**
* 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 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();
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());
}
/**
* 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 net.dv8tion.jda.api.entities.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 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);
if (!getGuild().getSelfMember().hasAccess(this))
throw new MissingAccessException(this, Permission.VIEW_CHANNEL);
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 net.dv8tion.jda.api.entities.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();
}