Class RestChannel


  • public class RestChannel
    extends Object
    Represents a guild or DM channel within Discord.
    • Method Detail

      • create

        public static RestChannel create​(RestClient restClient,
                                         Snowflake id)
        Create a RestChannel with the given parameters.
        Parameters:
        restClient - REST API resources
        id - the ID of this channel
      • getId

        public Snowflake getId()
        Returns the ID of this channel.
        Returns:
        The ID of this channel
      • getData

        public Mono<discord4j.discordjson.json.ChannelData> getData()
        Retrieve this channel's data upon subscription.
        Returns:
        a Mono where, upon successful completion, emits the ChannelData belonging to this channel. If an error is received, it is emitted through the Mono.
        See Also:
        Get Channel
      • message

        public RestMessage message​(Snowflake messageId)
        Return a RestMessage belonging to this channel. This method does not perform any API request.
        Parameters:
        messageId - the message ID under this channel
        Returns:
        a RestMessage represented by the given parameters.
      • modify

        public Mono<discord4j.discordjson.json.ChannelData> modify​(discord4j.discordjson.json.ChannelModifyRequest request,
                                                                   @Nullable
                                                                   String reason)
        Request to edit this text channel using a given ChannelModifyRequest as body and optionally, a reason.
        Parameters:
        request - request body used to create a new message
        reason - a reason for this action, can be null
        Returns:
        a Mono where, upon successful completion, emits the edited ChannelData. If an error is received, it is emitted through the Mono.
        See Also:
        Modify Channel
      • delete

        public Mono<Void> delete​(@Nullable
                                 String reason)
        Request to delete this channel while optionally specifying a reason.
        Parameters:
        reason - a reason for this action, can be null
        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.
        See Also:
        Delete/Close Channel
      • getMessagesBefore

        public Flux<discord4j.discordjson.json.MessageData> getMessagesBefore​(Snowflake messageId)
        Request 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)

        Parameters:
        messageId - The ID of the newest message to retrieve.
        Returns:
        A Flux that continually emits all messages before the specified ID. If an error is received, it is emitted through the Flux.
        See Also:
        Get Channel Messages
      • getMessagesAfter

        public Flux<discord4j.discordjson.json.MessageData> getMessagesAfter​(Snowflake messageId)
        Request 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)

        Parameters:
        messageId - the ID of the oldest message to retrieve.
        Returns:
        a Flux that continually emits all messages after the specified ID. If an error is received, it is emitted through the Flux.
        See Also:
        Get Channel Messages
      • getRestMessage

        public RestMessage getRestMessage​(Snowflake messageId)
        Create a RestMessage entity for a given ID under this channel. This method does not perform any network request.
        Parameters:
        messageId - the message's ID
        Returns:
        a RestMessage facade for the given message under this channel to perform actions on it
      • createMessage

        public Mono<discord4j.discordjson.json.MessageData> createMessage​(discord4j.discordjson.json.MessageCreateRequest request)
        Request to create a message using a given MessageCreateRequest as body. If you want to include attachments to your message, see createMessage(MultipartRequest).
        Parameters:
        request - request body used to create a new message
        Returns:
        a Mono where, upon successful completion, emits the created MessageData. If an error is received, it is emitted through the Mono.
        See Also:
        Create Message
      • createMessage

        public Mono<discord4j.discordjson.json.MessageData> createMessage​(MultipartRequest<discord4j.discordjson.json.MessageCreateRequest> request)
        Request to create a message using a given MultipartRequest as body. A MultipartRequest is a custom object allowing you to add attachments to a message.
        Parameters:
        request - request body used to create a new message
        Returns:
        a Mono where, upon successful completion, emits the created MessageData. If an error is received, it is emitted through the Mono.
        See Also:
        Create Message
      • createMessage

        public Mono<discord4j.discordjson.json.MessageData> createMessage​(String content)
        Wrapper for createMessage(MessageCreateRequest) taking only message content.
        Parameters:
        content - The content of the message
        Returns:
        a Mono where, upon successful completion, emits the created MessageData. If an error is received, it is emitted through the Mono.
      • createMessage

        public Mono<discord4j.discordjson.json.MessageData> createMessage​(discord4j.discordjson.json.EmbedData embed)
        Wrapper for createMessage(MessageCreateRequest) taking an embed only.
        Parameters:
        embed - The embed of the message
        Returns:
        a Mono where, upon successful completion, emits the created MessageData. If an error is received, it is emitted through the Mono.
      • bulkDelete

        public Flux<Snowflake> bulkDelete​(Publisher<Snowflake> messageIds)
        Request to bulk delete the supplied message IDs.
        Parameters:
        messageIds - a Publisher to supply the message IDs to bulk delete.
        Returns:
        a Flux that continually emits message IDs that were not bulk deleted (typically if the ID was older than 2 weeks). If an error is received, it is emitted through the Flux.
        See Also:
        Bulk Delete Messages
      • editChannelPermissions

        public Mono<Void> editChannelPermissions​(Snowflake targetId,
                                                 discord4j.discordjson.json.PermissionsEditRequest request,
                                                 @Nullable
                                                 String reason)
        Request to edit channel permission overwrites for the given member or role while optionally specifying a reason.
        Parameters:
        targetId - the ID of the member or role to add the overwrite for
        request - the overwrite request to edit
        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
        See Also:
        Edit Channel Permissions
      • getInvites

        public Flux<discord4j.discordjson.json.InviteData> getInvites()
        Request to retrieve this channel's invites.
        Returns:
        a Flux that continually emits this channel's invites. If an error is received, it is emitted through the Flux.
        See Also:
        Get Channel Invites
      • createInvite

        public Mono<discord4j.discordjson.json.InviteData> createInvite​(discord4j.discordjson.json.InviteCreateRequest request,
                                                                        @Nullable
                                                                        String reason)
        Request to create an invite.
        Parameters:
        request - request body used to create a new invite
        reason - the reason, if present
        Returns:
        a Mono where, upon successful completion, emits the created InviteData. If an error is received, it is emitted through the Mono.
        See Also:
        Create Channel Invite
      • deleteChannelPermission

        public Mono<Void> deleteChannelPermission​(Snowflake targetId,
                                                  @Nullable
                                                  String reason)
        Request to delete this permission overwrite while optionally specifying a reason.
        Parameters:
        reason - the reason, if present.
        Returns:
        a Mono where, upon successful completion, emits nothing; indicating the permission overwrite has been deleted. If an error is received, it is emitted through the Mono.
        See Also:
        Delete Channel Permission
      • follow

        public Mono<discord4j.discordjson.json.FollowedChannelData> follow​(discord4j.discordjson.json.NewsChannelFollowRequest request)
        Requests to follow this channel. Only works if this channel represents a news channel. Following this channel will create a webhook in a chosen target channel where 'MANAGE_WEBHOOKS' permission is granted.
        Parameters:
        request - the request to follow this channel
        Returns:
        A Mono where, upon successful completion, emits the data indicating that the channel has been followed. If an error is received, it is emitted through the Mono.
      • type

        public Mono<Void> type()
        Request 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.
        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.
        See Also:
        Trigger Typing Indicator
      • getPinnedMessages

        public Flux<discord4j.discordjson.json.MessageData> getPinnedMessages()
        Request to retrieve all the pinned messages for this channel.
        Returns:
        a Flux that continually emits all the pinned messages for this channel. If an error is received, it is emitted through the Flux.
        See Also:
        Get Pinned Messages
      • addPinnedMessage

        public Mono<Void> addPinnedMessage​(Snowflake messageId)
        Request to pin a message in this channel.
        Returns:
        A Mono where, upon successful completion, emits nothing; indicating the messaged was pinned. If an error is received, it is emitted through the Mono.
      • deletePinnedMessage

        public Mono<Void> deletePinnedMessage​(Snowflake messageId)
        Request to unpin a message in this channel.
        Returns:
        A Mono where, upon successful completion, emits nothing; indicating the message was unpinned. If an error is received, it is emitted through the Mono.
      • addGroupDMRecipient

        public Mono<Void> addGroupDMRecipient​(Snowflake userId,
                                              discord4j.discordjson.json.GroupAddRecipientRequest request)
      • deleteGroupDMRecipient

        public Mono<Void> deleteGroupDMRecipient​(Snowflake userId)
      • getWebhooks

        public Flux<discord4j.discordjson.json.WebhookData> getWebhooks()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object