public final class TextChannel extends Object
Channel.Type
Constructor and Description |
---|
TextChannel(GatewayDiscordClient gateway,
discord4j.discordjson.json.ChannelData data)
Constructs an
TextChannel with an associated ServiceMediator and Discord data. |
Modifier and Type | Method and Description |
---|---|
Mono<Void> |
addMemberOverwrite(Snowflake memberId,
PermissionOverwrite overwrite,
String reason)
Requests to add a permission overwrite for the given member while optionally specifying a reason.
|
Mono<Void> |
addRoleOverwrite(Snowflake roleId,
PermissionOverwrite overwrite,
String reason)
Requests to add a permission overwrite for the given role while optionally specifying a reason.
|
Flux<Snowflake> |
bulkDelete(Publisher<Snowflake> messageIds)
Requests to bulk delete the supplied message IDs.
|
Mono<ExtendedInvite> |
createInvite(Consumer<? super InviteCreateSpec> spec)
Requests to create an invite.
|
Mono<Message> |
createMessage(Consumer<? super MessageCreateSpec> spec)
Requests to create a message.
|
Mono<Webhook> |
createWebhook(Consumer<? super WebhookCreateSpec> spec)
Requests to create a webhook.
|
Mono<Void> |
delete(String reason)
Requests to delete this channel while optionally specifying a reason.
|
Mono<TextChannel> |
edit(Consumer<? super TextChannelEditSpec> spec)
Requests to edit this text channel.
|
boolean |
equals(Object obj) |
Mono<Category> |
getCategory()
Requests to retrieve the category for this channel, if present.
|
Mono<Category> |
getCategory(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the category for this channel, if present, using the given retrieval strategy.
|
Optional<Snowflake> |
getCategoryId()
Gets the ID of the category for this channel, if present.
|
GatewayDiscordClient |
getClient()
Returns the
GatewayDiscordClient that created this object. |
Mono<PermissionSet> |
getEffectivePermissions(Snowflake memberId)
Gets the permissions for the given member, taking into account permission overwrites in this channel.
|
Mono<Guild> |
getGuild()
Requests to retrieve the guild this channel is associated to.
|
Mono<Guild> |
getGuild(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the guild this channel is associated to, using the given retrieval strategy.
|
Snowflake |
getGuildId()
Gets the ID of the guild this channel is associated to.
|
Snowflake |
getId()
Gets the Snowflake that uniquely identifies this entity.
|
Flux<ExtendedInvite> |
getInvites()
Requests to retrieve this channel's invites.
|
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.
|
Flux<Member> |
getMembers()
Returns all members in the guild which have access to view this channel.
|
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.
|
String |
getName()
Gets the name of the channel.
|
Optional<ExtendedPermissionOverwrite> |
getOverwriteForMember(Snowflake memberId)
Gets the permission overwrite targeting the given member.
|
Optional<ExtendedPermissionOverwrite> |
getOverwriteForRole(Snowflake roleId)
Gets the permission overwrite targeting the given role.
|
Set<ExtendedPermissionOverwrite> |
getPermissionOverwrites()
Gets the permission overwrites for this channel.
|
Flux<Message> |
getPinnedMessages()
Requests to retrieve all the pinned messages for this channel.
|
Mono<Integer> |
getPosition()
Requests to retrieve the position of the channel relative to other channels in the guild.
|
int |
getRateLimitPerUser()
Gets the amount of seconds an user has to wait before sending another message (0-120).
|
int |
getRawPosition()
Gets the raw position of the channel as exposed by Discord.
|
RestChannel |
getRestChannel()
Return a
RestChannel handle to execute REST API operations on this entity. |
Optional<String> |
getTopic()
Gets the channel topic, if present.
|
Channel.Type |
getType()
Gets the type of channel.
|
Flux<Webhook> |
getWebhooks()
Requests to retrieve the webhooks of the channel.
|
int |
hashCode() |
boolean |
isNsfw()
Gets whether this channel is considered NSFW (Not Safe For Work).
|
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.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addMemberOverwrite, addRoleOverwrite
delete, delete, getMention, getRestChannel, getType
getClient
createEmbed, createMessage
public TextChannel(GatewayDiscordClient gateway, discord4j.discordjson.json.ChannelData data)
TextChannel
with an associated ServiceMediator and Discord data.gateway
- The GatewayDiscordClient
associated to this object, must be non-null.data
- The raw data as represented by Discord, must be non-null.public int getRateLimitPerUser()
Bots, as well as users with the permission manage_messages
or manage_channel
, are unaffected.
public boolean isNsfw()
true
if this channel is considered NSFW (Not Safe For Work), false
otherwise.public Mono<TextChannel> edit(Consumer<? super TextChannelEditSpec> spec)
spec
- A Consumer
that provides a "blank" TextChannelEditSpec
to be operated on.Mono
where, upon successful completion, emits the edited TextChannel
. If an error is
received, it is emitted through the Mono
.public String toString()
public Snowflake getGuildId()
GuildChannel
getGuildId
in interface GuildChannel
public Mono<Guild> getGuild()
GuildChannel
getGuild
in interface GuildChannel
Mono
where, upon successful completion, emits the guild
this channel is
associated to. If an error is received, it is emitted through the Mono
.public Mono<Guild> getGuild(EntityRetrievalStrategy retrievalStrategy)
GuildChannel
getGuild
in interface GuildChannel
retrievalStrategy
- the strategy to use to get the guildMono
where, upon successful completion, emits the guild
this channel is
associated to. If an error is received, it is emitted through the Mono
.public Set<ExtendedPermissionOverwrite> getPermissionOverwrites()
GuildChannel
getPermissionOverwrites
in interface GuildChannel
public Optional<ExtendedPermissionOverwrite> getOverwriteForMember(Snowflake memberId)
GuildChannel
getOverwriteForMember
in interface GuildChannel
memberId
- The ID of the member to get the overwrite for.public Optional<ExtendedPermissionOverwrite> getOverwriteForRole(Snowflake roleId)
GuildChannel
getOverwriteForRole
in interface GuildChannel
roleId
- The ID of the role to get the overwrite for.public Mono<PermissionSet> getEffectivePermissions(Snowflake memberId)
GuildChannel
getEffectivePermissions
in interface GuildChannel
memberId
- The ID of the member to get permissions for.public String getName()
GuildChannel
getName
in interface GuildChannel
public int getRawPosition()
GuildChannel
getRawPosition
in interface GuildChannel
public Mono<Integer> getPosition()
GuildChannel
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)
getPosition
in interface GuildChannel
Mono
where, upon successful completion, emits the position of the channel. If an error is
received, it is emitted through the Mono
.public Mono<Void> addMemberOverwrite(Snowflake memberId, PermissionOverwrite overwrite, @Nullable String reason)
GuildChannel
addMemberOverwrite
in interface GuildChannel
memberId
- The ID of the member to add the overwrite for.overwrite
- The overwrite to add.reason
- The reason, if present.Mono
where, upon successful completion, emits nothing; If an error is received, it is emitted
through the Mono
.public Mono<Void> addRoleOverwrite(Snowflake roleId, PermissionOverwrite overwrite, @Nullable String reason)
GuildChannel
addRoleOverwrite
in interface GuildChannel
roleId
- The ID of the role to add the overwrite for.overwrite
- The overwrite to add.reason
- The reason, if present.Mono
where, upon successful completion, emits nothing; If an error is received, it is emitted
through the Mono
.public Optional<Snowflake> getLastMessageId()
MessageChannel
getLastMessageId
in interface MessageChannel
public Mono<Message> getLastMessage()
MessageChannel
getLastMessage
in interface MessageChannel
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
.public Mono<Message> getLastMessage(EntityRetrievalStrategy retrievalStrategy)
MessageChannel
getLastMessage
in interface MessageChannel
retrievalStrategy
- the strategy to use to get the last messageMono
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
.public Optional<Instant> getLastPinTimestamp()
MessageChannel
getLastPinTimestamp
in interface MessageChannel
public Mono<Message> createMessage(Consumer<? super MessageCreateSpec> spec)
MessageChannel
createMessage
in interface MessageChannel
spec
- A Consumer
that provides a "blank" MessageCreateSpec
to be operated on.Mono
where, upon successful completion, emits the created Message
. If an error is
received, it is emitted through the Mono
.public Mono<Void> type()
MessageChannel
type
in interface MessageChannel
Mono
which completes upon successful triggering of the typing indicator in this channel. If
an error is received, it is emitted through the Mono
.public Flux<Long> typeUntil(Publisher<?> until)
MessageChannel
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"))
typeUntil
in interface MessageChannel
until
- The companion Publisher
that signals when to stop triggering the typing indicator.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
.public Flux<Message> getMessagesBefore(Snowflake messageId)
MessageChannel
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)
getMessagesBefore
in interface MessageChannel
messageId
- The ID of the newest message to retrieve. Use Snowflake.of(Instant)
to retrieve a
time-based ID.Flux
that continually emits all messages
before the specified ID.
If an error is received, it is emitted through the Flux
.public Flux<Message> getMessagesAfter(Snowflake messageId)
MessageChannel
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)
getMessagesAfter
in interface MessageChannel
messageId
- The ID of the oldest message to retrieve. Use Snowflake.of(Instant)
to retrieve a
time-based ID.Flux
that continually emits all messages
after the specified ID.
If an error is received, it is emitted through the Flux
.public Mono<Message> getMessageById(Snowflake id)
MessageChannel
getMessageById
in interface MessageChannel
id
- The ID of the message.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
.public Mono<Message> getMessageById(Snowflake id, EntityRetrievalStrategy retrievalStrategy)
MessageChannel
getMessageById
in interface MessageChannel
id
- The ID of the message.retrievalStrategy
- the strategy to use to get the messageMono
where, upon successful completion, emits the Message
as represented by the
supplied ID. If an error is received, it is emitted through the Mono
.public Flux<Message> getPinnedMessages()
MessageChannel
getPinnedMessages
in interface MessageChannel
Flux
that continually emits all the pinned messages for this channel. If an error is received,
it is emitted through the Flux
.public Optional<Snowflake> getCategoryId()
CategorizableChannel
getCategoryId
in interface CategorizableChannel
public Mono<Category> getCategory()
CategorizableChannel
getCategory
in interface CategorizableChannel
Mono
where, upon successful completion, emits the category
this channel, if
present. If an error is received, it is emitted through the Mono
.public Mono<Category> getCategory(EntityRetrievalStrategy retrievalStrategy)
CategorizableChannel
getCategory
in interface CategorizableChannel
retrievalStrategy
- the strategy to use to get the categoryMono
where, upon successful completion, emits the category
this channel, if
present. If an error is received, it is emitted through the Mono
.public Mono<ExtendedInvite> createInvite(Consumer<? super InviteCreateSpec> spec)
CategorizableChannel
createInvite
in interface CategorizableChannel
spec
- A Consumer
that provides a "blank" InviteCreateSpec
to be operated on.Mono
where, upon successful completion, emits the created ExtendedInvite
. If an error
is received, it is emitted through the Mono
.public Flux<ExtendedInvite> getInvites()
CategorizableChannel
getInvites
in interface CategorizableChannel
Flux
that continually emits this channel's invites
. If an error is
received, it is emitted through the Flux
.public Optional<String> getTopic()
getTopic
in interface GuildMessageChannel
public Flux<Snowflake> bulkDelete(Publisher<Snowflake> messageIds)
bulkDelete
in interface GuildMessageChannel
messageIds
- A Publisher
to supply the message IDs to bulk delete.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
.public Mono<Webhook> createWebhook(Consumer<? super WebhookCreateSpec> spec)
createWebhook
in interface GuildMessageChannel
spec
- A Consumer
that provides a "blank" WebhookCreateSpec
to be operated on.Mono
where, upon successful completion, emits the created Webhook
. If an error
is received, it is emitted through the Mono
.public Flux<Webhook> getWebhooks()
getWebhooks
in interface GuildMessageChannel
Flux
that continually emits the webhooks
of the channel. If an error is
received, it is emitted through the Flux
.public Flux<Member> getMembers()
getMembers
in interface GuildMessageChannel
Flux
that continually emits all members from Guild.getMembers()
which have access to
view this channel Permission.VIEW_CHANNEL
public final GatewayDiscordClient getClient()
DiscordObject
GatewayDiscordClient
that created this object. Methods in it are exclusively based on the
entity cache or Store
in use. Refer to calling getClient().rest()
to access a
DiscordClient
that is capable of requesting entities directly from the REST API.getClient
in interface DiscordObject
GatewayDiscordClient
associated to this object.public final Snowflake getId()
Entity
public RestChannel getRestChannel()
Channel
RestChannel
handle to execute REST API operations on this entity.getRestChannel
in interface Channel
public final Channel.Type getType()
Channel
public final Mono<Void> delete(@Nullable String reason)
Channel