Class PrivateChannel
- java.lang.Object
-
- discord4j.core.object.entity.channel.PrivateChannel
-
- All Implemented Interfaces:
DiscordObject,Channel,MessageChannel,Entity
public final class PrivateChannel extends Object
A Discord private channel (also known as a DM channel).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface discord4j.core.object.entity.channel.Channel
Channel.Type
-
-
Constructor Summary
Constructors Constructor Description PrivateChannel(GatewayDiscordClient gateway, discord4j.discordjson.json.ChannelData data)Constructs anPrivateChannelwith an associatedGatewayDiscordClientand Discord data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Mono<Message>createMessage(discord4j.core.spec.MessageCreateSpec spec)Requests to create a message.Mono<Message>createMessage(Consumer<? super LegacyMessageCreateSpec> spec)Requests to create a message.Mono<Void>delete(String reason)Requests to delete this channel while optionally specifying a reason.booleanequals(Object obj)GatewayDiscordClientgetClient()Returns theGatewayDiscordClientthat created this object.SnowflakegetId()Gets the Snowflake that uniquely identifies this entity.Mono<Message>getLastMessage()Requests to retrieve the last message sent in this channel, if present.Mono<Message>getLastMessage(EntityRetrievalStrategy retrievalStrategy)Requests to retrieve the last message sent in this channel, if present, using the given retrieval strategy.Optional<Snowflake>getLastMessageId()Gets the ID of the last message sent in this channel, if present.Optional<Instant>getLastPinTimestamp()Gets when the last pinned message was pinned, if present.Mono<Message>getMessageById(Snowflake id)Requests to retrieve the message as represented by the supplied ID.Mono<Message>getMessageById(Snowflake id, EntityRetrievalStrategy retrievalStrategy)Requests to retrieve the message as represented by the supplied ID, using the given retrieval strategy.Flux<Message>getMessagesAfter(Snowflake messageId)Requests to retrieve all messages after the specified ID.Flux<Message>getMessagesBefore(Snowflake messageId)Requests to retrieve all messages before the specified ID.Flux<Message>getPinnedMessages()Requests to retrieve all the pinned messages for this channel.Set<Snowflake>getRecipientIds()Gets the IDs of the recipients for this private channel.Set<User>getRecipients()Gets the recipients for this private channel.RestChannelgetRestChannel()Return aRestChannelhandle to execute REST API operations on this entity.Channel.TypegetType()Gets the type of channel.inthashCode()StringtoString()Mono<Void>type()Requests to trigger the typing indicator in this channel.Flux<Long>typeUntil(Publisher<?> until)Requests to trigger the typing indicator in this channel.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface discord4j.core.object.entity.channel.Channel
delete, delete, getMention, getRestChannel, getType
-
Methods inherited from interface discord4j.core.object.DiscordObject
getClient
-
Methods inherited from interface discord4j.core.object.entity.channel.MessageChannel
createEmbed, createEmbed, createMessage, createMessage
-
-
-
-
Constructor Detail
-
PrivateChannel
public PrivateChannel(GatewayDiscordClient gateway, discord4j.discordjson.json.ChannelData data)
Constructs anPrivateChannelwith an associatedGatewayDiscordClientand Discord data.- Parameters:
gateway- TheGatewayDiscordClientassociated to this object, must be non-null.data- The raw data as represented by Discord, must be non-null.
-
-
Method Detail
-
getRecipientIds
public Set<Snowflake> getRecipientIds()
Gets the IDs of the recipients for this private channel.- Returns:
- The IDs of the recipients for this private channel.
-
getRecipients
public Set<User> getRecipients()
Gets the recipients for this private channel.- Returns:
- The recipients for this private channel.
-
toString
public String toString()
-
getLastMessageId
public final Optional<Snowflake> getLastMessageId()
Description copied from interface:MessageChannelGets the ID of the last message sent in this channel, if present.- Specified by:
getLastMessageIdin interfaceMessageChannel- Returns:
- The ID of the last message sent in this channel, if present.
-
getLastMessage
public final Mono<Message> getLastMessage()
Description copied from interface:MessageChannelRequests to retrieve the last message sent in this channel, if present.- Specified by:
getLastMessagein interfaceMessageChannel- Returns:
- A
Monowhere, upon successful completion, emits the lastmessagesent in this channel, if present. If an error is received, it is emitted through theMono.
-
getLastMessage
public Mono<Message> getLastMessage(EntityRetrievalStrategy retrievalStrategy)
Description copied from interface:MessageChannelRequests to retrieve the last message sent in this channel, if present, using the given retrieval strategy.- Specified by:
getLastMessagein interfaceMessageChannel- Parameters:
retrievalStrategy- the strategy to use to get the last message- Returns:
- A
Monowhere, upon successful completion, emits the lastmessagesent in this channel, if present. If an error is received, it is emitted through theMono.
-
getLastPinTimestamp
public final Optional<Instant> getLastPinTimestamp()
Description copied from interface:MessageChannelGets when the last pinned message was pinned, if present.- Specified by:
getLastPinTimestampin interfaceMessageChannel- Returns:
- When the last pinned message was pinned, if present.
-
createMessage
public final Mono<Message> createMessage(Consumer<? super LegacyMessageCreateSpec> spec)
Description copied from interface:MessageChannelRequests to create a message.- Specified by:
createMessagein interfaceMessageChannel- Parameters:
spec- AConsumerthat provides a "blank"LegacyMessageCreateSpecto be operated on.- Returns:
- A
Monowhere, upon successful completion, emits the createdMessage. If an error is received, it is emitted through theMono.
-
createMessage
public Mono<Message> createMessage(discord4j.core.spec.MessageCreateSpec spec)
Description copied from interface:MessageChannelRequests to create a message.- Specified by:
createMessagein interfaceMessageChannel- Parameters:
spec- an immutable object that specifies how to create the message- Returns:
- A
Monowhere, upon successful completion, emits the createdMessage. If an error is received, it is emitted through theMono. - See Also:
MessageCreateSpec.builder()
-
type
public final Mono<Void> type()
Description copied from interface:MessageChannelRequests 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:
typein interfaceMessageChannel- Returns:
- A
Monowhich completes upon successful triggering of the typing indicator in this channel. If an error is received, it is emitted through theMono.
-
typeUntil
public final Flux<Long> typeUntil(Publisher<?> until)
Description copied from interface:MessageChannelRequests 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:
typeUntilin interfaceMessageChannel- Parameters:
until- The companionPublisherthat signals when to stop triggering the typing indicator.- Returns:
- A
Fluxwhich 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 theFlux.
-
getMessagesBefore
public final Flux<Message> getMessagesBefore(Snowflake messageId)
Description copied from interface:MessageChannelRequests to retrieve all messages before the specified ID.The returned
Fluxwill emit items in reverse-chronological order (newest to oldest). It is recommended to limit the emitted items by invoking eitherFlux.takeWhile(Predicate)(to retrieve IDs within a specified range) orFlux.take(long)(to retrieve a specific amount of IDs).The following example will get all messages from
messageIdtomyOtherMessageId:getMessagesBefore(messageId).takeWhile(message -> message.getId().compareTo(myOtherMessageId) >= 0)- Specified by:
getMessagesBeforein interfaceMessageChannel- Parameters:
messageId- The ID of the newest message to retrieve. UseSnowflake.of(Instant)to retrieve a time-based ID.- Returns:
- A
Fluxthat continually emits allmessagesbefore the specified ID. If an error is received, it is emitted through theFlux.
-
getMessagesAfter
public final Flux<Message> getMessagesAfter(Snowflake messageId)
Description copied from interface:MessageChannelRequests to retrieve all messages after the specified ID.The returned
Fluxwill emit items in chronological order (oldest to newest). It is recommended to limit the emitted items by invoking eitherFlux.takeWhile(Predicate)(to retrieve IDs within a specified range) orFlux.take(long)(to retrieve a specific amount of IDs).The following example will get all messages from
messageIdtomyOtherMessageId:getMessagesAfter(messageId).takeWhile(message -> message.getId().compareTo(myOtherMessageId) <= 0)- Specified by:
getMessagesAfterin interfaceMessageChannel- Parameters:
messageId- The ID of the oldest message to retrieve. UseSnowflake.of(Instant)to retrieve a time-based ID.- Returns:
- A
Fluxthat continually emits allmessagesafter the specified ID. If an error is received, it is emitted through theFlux.
-
getMessageById
public final Mono<Message> getMessageById(Snowflake id)
Description copied from interface:MessageChannelRequests to retrieve the message as represented by the supplied ID.- Specified by:
getMessageByIdin interfaceMessageChannel- Parameters:
id- The ID of the message.- Returns:
- A
Monowhere, upon successful completion, emits theMessageas represented by the supplied ID. If an error is received, it is emitted through theMono.
-
getMessageById
public Mono<Message> getMessageById(Snowflake id, EntityRetrievalStrategy retrievalStrategy)
Description copied from interface:MessageChannelRequests to retrieve the message as represented by the supplied ID, using the given retrieval strategy.- Specified by:
getMessageByIdin interfaceMessageChannel- Parameters:
id- The ID of the message.retrievalStrategy- the strategy to use to get the message- Returns:
- A
Monowhere, upon successful completion, emits theMessageas represented by the supplied ID. If an error is received, it is emitted through theMono.
-
getPinnedMessages
public final Flux<Message> getPinnedMessages()
Description copied from interface:MessageChannelRequests to retrieve all the pinned messages for this channel.- Specified by:
getPinnedMessagesin interfaceMessageChannel- Returns:
- A
Fluxthat continually emits all the pinned messages for this channel. If an error is received, it is emitted through theFlux.
-
getClient
public final GatewayDiscordClient getClient()
Description copied from interface:DiscordObjectReturns theGatewayDiscordClientthat created this object. Methods in it are exclusively based on the entity cache orStorein use. Refer to callinggetClient().rest()to access aDiscordClientthat is capable of requesting entities directly from the REST API.- Specified by:
getClientin interfaceDiscordObject- Returns:
- The
GatewayDiscordClientassociated to this object.
-
getId
public final Snowflake getId()
Description copied from interface:EntityGets the Snowflake that uniquely identifies this entity.
-
getRestChannel
public RestChannel getRestChannel()
Description copied from interface:ChannelReturn aRestChannelhandle to execute REST API operations on this entity.- Specified by:
getRestChannelin interfaceChannel
-
getType
public final Channel.Type getType()
Description copied from interface:ChannelGets the type of channel.
-
delete
public final Mono<Void> delete(@Nullable String reason)
Description copied from interface:ChannelRequests to delete this channel while optionally specifying a reason.
-
-