Class NewsChannel

    • Constructor Detail

      • NewsChannel

        public NewsChannel​(GatewayDiscordClient gateway,
                           discord4j.discordjson.json.ChannelData data)
        Constructs an NewsChannel with an associated GatewayDiscordClient and Discord data.
        Parameters:
        gateway - The GatewayDiscordClient associated to this object, must be non-null.
        data - The raw data as represented by Discord, must be non-null.
    • Method Detail

      • edit

        public discord4j.core.spec.NewsChannelEditMono edit()
        Requests to edit this news channel. Properties specifying how to edit this news channel can be set via the withXxx methods of the returned NewsChannelEditMono.
        Returns:
        A NewsChannelEditMono where, upon successful completion, emits the edited NewsChannel. If an error is received, it is emitted through the NewsChannelEditMono.
      • edit

        public Mono<NewsChannel> edit​(discord4j.core.spec.NewsChannelEditSpec spec)
        Requests to edit this news channel.
        Parameters:
        spec - an immutable object that specifies how to edit this news channel
        Returns:
        A Mono where, upon successful completion, emits the edited NewsChannel. If an error is received, it is emitted through the Mono.
      • follow

        public Mono<FollowedChannel> follow​(Snowflake targetChannelId)
        Requests to follow this news channel. Following will create a webhook in the channel which ID is specified. Requires 'MANAGE_WEBHOOKS' permission.
        Parameters:
        targetChannelId - the ID of the channel where to create the follow webhook
        Returns:
        a FollowedChannel object containing a reference to this news channel and allowing to retrieve the webhook created.
      • toString

        public String toString()
      • getLastMessageId

        public Optional<Snowflake> getLastMessageId()
        Description copied from interface: MessageChannel
        Gets the ID of the last message sent in this channel, if present.
        Specified by:
        getLastMessageId in interface MessageChannel
        Returns:
        The ID of the last message sent in this channel, if present.
      • getLastMessage

        public Mono<Message> getLastMessage()
        Description copied from interface: MessageChannel
        Requests to retrieve the last message sent in this channel, if present.
        Specified by:
        getLastMessage in interface MessageChannel
        Returns:
        A Mono where, upon successful completion, emits the last message sent in this channel, if present. If an error is received, it is emitted through the Mono.
      • getLastMessage

        public Mono<Message> getLastMessage​(EntityRetrievalStrategy retrievalStrategy)
        Description copied from interface: MessageChannel
        Requests to retrieve the last message sent in this channel, if present, using the given retrieval strategy.
        Specified by:
        getLastMessage in interface MessageChannel
        Parameters:
        retrievalStrategy - the strategy to use to get the last message
        Returns:
        A Mono where, upon successful completion, emits the last message sent in this channel, if present. If an error is received, it is emitted through the Mono.
      • createMessage

        public Mono<Message> createMessage​(discord4j.core.spec.MessageCreateSpec spec)
        Description copied from interface: MessageChannel
        Requests to create a message.
        Specified by:
        createMessage in interface MessageChannel
        Parameters:
        spec - an immutable object that specifies how to create the message
        Returns:
        A Mono where, upon successful completion, emits the created Message. If an error is received, it is emitted through the Mono.
        See Also:
        MessageCreateSpec.builder()
      • type

        public Mono<Void> type()
        Description copied from interface: MessageChannel
        Requests to trigger the typing indicator in this channel. A single invocation of this method will trigger the indicator for 10 seconds or until the bot sends a message in this channel.
        Specified by:
        type in interface MessageChannel
        Returns:
        A Mono which completes upon successful triggering of the typing indicator in this channel. If an error is received, it is emitted through the Mono.
      • typeUntil

        public Flux<Long> typeUntil​(Publisher<?> until)
        Description copied from interface: MessageChannel
        Requests to trigger the typing indicator in this channel. It will be continuously triggered every 10 seconds until the given publisher emits.

        This method cannot stop the typing indicator during the 10 second duration. It simply checks every 10 seconds whether to trigger the indicator again depending on if the publisher emitted. For example, the following code will show the typing indicator for 10 seconds, not 5:

         
         channel.typeUntil(Mono.delay(Duration.ofSeconds(5))
         
         

        The only way to stop the typing indicator during the 10 second duration is to send a message in the channel. For example, the following code will show the typing indicator until the message is sent:

         
         channel.typeUntil(channel.createMessage("Hello"))
         
         
        Specified by:
        typeUntil in interface MessageChannel
        Parameters:
        until - The companion Publisher that signals when to stop triggering the typing indicator.
        Returns:
        A Flux which continually emits each time the typing indicator is triggered and completes when it will no longer be triggered. If an error is received, it is emitted through the Flux.
      • getMessagesBefore

        public Flux<Message> getMessagesBefore​(Snowflake messageId)
        Description copied from interface: MessageChannel
        Requests to retrieve all messages before the specified ID.

        The returned Flux will emit items in reverse-chronological order (newest to oldest). It is recommended to limit the emitted items by invoking either Flux.takeWhile(Predicate) (to retrieve IDs within a specified range) or Flux.take(long) (to retrieve a specific amount of IDs).

        The following example will get all messages from messageId to myOtherMessageId: getMessagesBefore(messageId).takeWhile(message -> message.getId().compareTo(myOtherMessageId) >= 0)

        Specified by:
        getMessagesBefore in interface MessageChannel
        Parameters:
        messageId - The ID of the newest message to retrieve. Use Snowflake.of(Instant) to retrieve a time-based ID.
        Returns:
        A Flux that continually emits all messages before the specified ID. If an error is received, it is emitted through the Flux.
      • getMessagesAfter

        public Flux<Message> getMessagesAfter​(Snowflake messageId)
        Description copied from interface: MessageChannel
        Requests to retrieve all messages after the specified ID.

        The returned Flux will emit items in chronological order (oldest to newest). It is recommended to limit the emitted items by invoking either Flux.takeWhile(Predicate) (to retrieve IDs within a specified range) or Flux.take(long) (to retrieve a specific amount of IDs).

        The following example will get all messages from messageId to myOtherMessageId: getMessagesAfter(messageId).takeWhile(message -> message.getId().compareTo(myOtherMessageId) <= 0)

        Specified by:
        getMessagesAfter in interface MessageChannel
        Parameters:
        messageId - The ID of the oldest message to retrieve. Use Snowflake.of(Instant) to retrieve a time-based ID.
        Returns:
        A Flux that continually emits all messages after the specified ID. If an error is received, it is emitted through the Flux.
      • getMessageById

        public Mono<Message> getMessageById​(Snowflake id)
        Description copied from interface: MessageChannel
        Requests to retrieve the message as represented by the supplied ID.
        Specified by:
        getMessageById in interface MessageChannel
        Parameters:
        id - The ID of the message.
        Returns:
        A Mono where, upon successful completion, emits the Message as represented by the supplied ID. If an error is received, it is emitted through the Mono.
      • getMessageById

        public Mono<Message> getMessageById​(Snowflake id,
                                            EntityRetrievalStrategy retrievalStrategy)
        Description copied from interface: MessageChannel
        Requests to retrieve the message as represented by the supplied ID, using the given retrieval strategy.
        Specified by:
        getMessageById in interface MessageChannel
        Parameters:
        id - The ID of the message.
        retrievalStrategy - the strategy to use to get the message
        Returns:
        A Mono where, upon successful completion, emits the Message as represented by the supplied ID. If an error is received, it is emitted through the Mono.
      • getPinnedMessages

        public Flux<Message> getPinnedMessages()
        Description copied from interface: MessageChannel
        Requests to retrieve all the pinned messages for this channel.
        Specified by:
        getPinnedMessages in interface MessageChannel
        Returns:
        A Flux that continually emits all the pinned messages for this channel. If an error is received, it is emitted through the Flux.
      • getCategory

        public Mono<Category> getCategory()
        Description copied from interface: CategorizableChannel
        Requests to retrieve the category for this channel, if present.
        Specified by:
        getCategory in interface CategorizableChannel
        Returns:
        A Mono where, upon successful completion, emits the category this channel, if present. If an error is received, it is emitted through the Mono.
      • getCategory

        public Mono<Category> getCategory​(EntityRetrievalStrategy retrievalStrategy)
        Description copied from interface: CategorizableChannel
        Requests to retrieve the category for this channel, if present, using the given retrieval strategy.
        Specified by:
        getCategory in interface CategorizableChannel
        Parameters:
        retrievalStrategy - the strategy to use to get the category
        Returns:
        A Mono where, upon successful completion, emits the category this channel, if present. If an error is received, it is emitted through the Mono.
      • createInvite

        public Mono<ExtendedInvite> createInvite​(discord4j.core.spec.InviteCreateSpec spec)
        Description copied from interface: CategorizableChannel
        Requests to create an invite.
        Specified by:
        createInvite in interface CategorizableChannel
        Parameters:
        spec - an immutable object that specifies how to create the invite
        Returns:
        A Mono where, upon successful completion, emits the created ExtendedInvite. If an error is received, it is emitted through the Mono.
      • getGuildId

        public final Snowflake getGuildId()
        Description copied from interface: GuildChannel
        Gets the ID of the guild this channel is associated to.
        Specified by:
        getGuildId in interface GuildChannel
        Returns:
        The ID of the guild this channel is associated to.
      • getGuild

        public final Mono<Guild> getGuild()
        Description copied from interface: GuildChannel
        Requests to retrieve the guild this channel is associated to.
        Specified by:
        getGuild in interface GuildChannel
        Returns:
        A Mono where, upon successful completion, emits the guild this channel is associated to. If an error is received, it is emitted through the Mono.
      • getGuild

        public Mono<Guild> getGuild​(EntityRetrievalStrategy retrievalStrategy)
        Description copied from interface: GuildChannel
        Requests to retrieve the guild this channel is associated to, using the given retrieval strategy.
        Specified by:
        getGuild in interface GuildChannel
        Parameters:
        retrievalStrategy - the strategy to use to get the guild
        Returns:
        A Mono where, upon successful completion, emits the guild this channel is associated to. If an error is received, it is emitted through the Mono.
      • getEffectivePermissions

        public Mono<PermissionSet> getEffectivePermissions​(Snowflake memberId)
        Description copied from interface: GuildChannel
        Gets the permissions for the given member, taking into account permission overwrites in this channel.
        Specified by:
        getEffectivePermissions in interface GuildChannel
        Parameters:
        memberId - The ID of the member to get permissions for.
        Returns:
        The permissions for the given member.
      • getEffectivePermissions

        public Mono<PermissionSet> getEffectivePermissions​(Member member)
        Description copied from interface: GuildChannel
        Gets the permissions for the given member, taking into account permission overwrites in this channel.
        Specified by:
        getEffectivePermissions in interface GuildChannel
        Parameters:
        member - The member to get permissions for.
        Returns:
        The permissions for the given member.
      • getName

        public final String getName()
        Description copied from interface: GuildChannel
        Gets the name of the channel.
        Specified by:
        getName in interface GuildChannel
        Returns:
        The name of the channel.
      • getRawPosition

        public int getRawPosition()
        Description copied from interface: GuildChannel
        Gets the raw position of the channel as exposed by Discord. This may or may not be accurate with relativity to other channels in the guild.
        Specified by:
        getRawPosition in interface GuildChannel
        Returns:
        The raw position of the channel.
      • getPosition

        public final Mono<Integer> getPosition()
        Description copied from interface: GuildChannel
        Requests to retrieve the position of the channel relative to other channels in the guild.

        This is determined by the index of this channel in the sorted list of channels of the guild.

        Warning: Because this method must sort the guild channels, it is inefficient to make repeated invocations for the same set of channels (meaning that channels haven't been added or removed). For example, instead of writing:

         
         guild.getChannels()
           .flatMap(c -> c.getPosition().map(pos -> c.getName() + " : " + pos))
         
         
        It would be much more efficient to write:
         
         guild.getChannels()
           .transform(OrderUtil::orderGuildChannels)
           .index((pos, c) -> c.getName() + " : " + pos)
         
         
        Specified by:
        getPosition in interface GuildChannel
        Returns:
        A Mono where, upon successful completion, emits the position of the channel. If an error is received, it is emitted through the Mono.
      • addMemberOverwrite

        public Mono<Void> addMemberOverwrite​(Snowflake memberId,
                                             PermissionOverwrite overwrite,
                                             @Nullable
                                             String reason)
        Description copied from interface: GuildChannel
        Requests to add a permission overwrite for the given member while optionally specifying a reason.
        Specified by:
        addMemberOverwrite in interface GuildChannel
        Parameters:
        memberId - The ID of the member to add the overwrite for.
        overwrite - The overwrite to add.
        reason - The reason, if present.
        Returns:
        A Mono where, upon successful completion, emits nothing; If an error is received, it is emitted through the Mono.
      • addRoleOverwrite

        public Mono<Void> addRoleOverwrite​(Snowflake roleId,
                                           PermissionOverwrite overwrite,
                                           @Nullable
                                           String reason)
        Description copied from interface: GuildChannel
        Requests to add a permission overwrite for the given role while optionally specifying a reason.
        Specified by:
        addRoleOverwrite in interface GuildChannel
        Parameters:
        roleId - The ID of the role to add the overwrite for.
        overwrite - The overwrite to add.
        reason - The reason, if present.
        Returns:
        A Mono where, upon successful completion, emits nothing; If an error is received, it is emitted through the Mono.
      • getId

        public final Snowflake getId()
        Description copied from interface: Entity
        Gets the Snowflake that uniquely identifies this entity.
        Specified by:
        getId in interface Entity
        Returns:
        The Snowflake that uniquely identifies this entity.
      • getType

        public final Channel.Type getType()
        Description copied from interface: Channel
        Gets the type of channel.
        Specified by:
        getType in interface Channel
        Returns:
        The type of channel.
      • delete

        public final Mono<Void> delete​(@Nullable
                                       String reason)
        Description copied from interface: Channel
        Requests to delete this channel while optionally specifying a reason.
        Specified by:
        delete in interface Channel
        Parameters:
        reason - The reason, if present.
        Returns:
        A Mono where, upon successful completion, emits nothing; indicating the channel has been deleted. If an error is received, it is emitted through the Mono.
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object