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 anPrivateChannel
with an associatedGatewayDiscordClient
and 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.boolean
equals(Object obj)
GatewayDiscordClient
getClient()
Returns theGatewayDiscordClient
that created this object.Snowflake
getId()
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.RestChannel
getRestChannel()
Return aRestChannel
handle to execute REST API operations on this entity.Channel.Type
getType()
Gets the type of channel.int
hashCode()
String
toString()
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 anPrivateChannel
with an associatedGatewayDiscordClient
and Discord data.- Parameters:
gateway
- TheGatewayDiscordClient
associated 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:MessageChannel
Gets the ID of the last message sent in this channel, if present.- Specified by:
getLastMessageId
in interfaceMessageChannel
- Returns:
- The ID of the last message sent in this channel, if present.
-
getLastMessage
public final Mono<Message> getLastMessage()
Description copied from interface:MessageChannel
Requests to retrieve the last message sent in this channel, if present.- Specified by:
getLastMessage
in interfaceMessageChannel
- Returns:
- A
Mono
where, upon successful completion, emits the lastmessage
sent 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:MessageChannel
Requests to retrieve the last message sent in this channel, if present, using the given retrieval strategy.- Specified by:
getLastMessage
in interfaceMessageChannel
- Parameters:
retrievalStrategy
- the strategy to use to get the last message- Returns:
- A
Mono
where, upon successful completion, emits the lastmessage
sent 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:MessageChannel
Gets when the last pinned message was pinned, if present.- Specified by:
getLastPinTimestamp
in 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:MessageChannel
Requests to create a message.- Specified by:
createMessage
in interfaceMessageChannel
- Parameters:
spec
- AConsumer
that provides a "blank"LegacyMessageCreateSpec
to be operated on.- Returns:
- A
Mono
where, 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:MessageChannel
Requests to create a message.- Specified by:
createMessage
in interfaceMessageChannel
- Parameters:
spec
- an immutable object that specifies how to create the message- Returns:
- A
Mono
where, 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: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 interfaceMessageChannel
- Returns:
- A
Mono
which 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: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 interfaceMessageChannel
- Parameters:
until
- The companionPublisher
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 theFlux
.
-
getMessagesBefore
public final 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 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
messageId
tomyOtherMessageId
:getMessagesBefore(messageId).takeWhile(message -> message.getId().compareTo(myOtherMessageId) >= 0)
- Specified by:
getMessagesBefore
in interfaceMessageChannel
- Parameters:
messageId
- The ID of the newest message to retrieve. UseSnowflake.of(Instant)
to retrieve a time-based ID.- Returns:
- A
Flux
that continually emits allmessages
before 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: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 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
messageId
tomyOtherMessageId
:getMessagesAfter(messageId).takeWhile(message -> message.getId().compareTo(myOtherMessageId) <= 0)
- Specified by:
getMessagesAfter
in interfaceMessageChannel
- Parameters:
messageId
- The ID of the oldest message to retrieve. UseSnowflake.of(Instant)
to retrieve a time-based ID.- Returns:
- A
Flux
that continually emits allmessages
after 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:MessageChannel
Requests to retrieve the message as represented by the supplied ID.- Specified by:
getMessageById
in interfaceMessageChannel
- Parameters:
id
- The ID of the message.- Returns:
- A
Mono
where, upon successful completion, emits theMessage
as 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:MessageChannel
Requests to retrieve the message as represented by the supplied ID, using the given retrieval strategy.- Specified by:
getMessageById
in interfaceMessageChannel
- Parameters:
id
- The ID of the message.retrievalStrategy
- the strategy to use to get the message- Returns:
- A
Mono
where, upon successful completion, emits theMessage
as 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:MessageChannel
Requests to retrieve all the pinned messages for this channel.- Specified by:
getPinnedMessages
in interfaceMessageChannel
- Returns:
- A
Flux
that 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:DiscordObject
Returns theGatewayDiscordClient
that created this object. Methods in it are exclusively based on the entity cache orStore
in use. Refer to callinggetClient().rest()
to access aDiscordClient
that is capable of requesting entities directly from the REST API.- Specified by:
getClient
in interfaceDiscordObject
- Returns:
- The
GatewayDiscordClient
associated to this object.
-
getId
public final Snowflake getId()
Description copied from interface:Entity
Gets the Snowflake that uniquely identifies this entity.
-
getRestChannel
public RestChannel getRestChannel()
Description copied from interface:Channel
Return aRestChannel
handle to execute REST API operations on this entity.- Specified by:
getRestChannel
in interfaceChannel
-
getType
public final Channel.Type getType()
Description copied from interface:Channel
Gets 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.
-
-