Interface MessageChannel

All Superinterfaces:
Channel, DiscordObject, Entity
All Known Subinterfaces:
GuildMessageChannel, TopLevelGuildMessageChannel
All Known Implementing Classes:
NewsChannel, PrivateChannel, TextChannel, ThreadChannel, VoiceChannel

public interface MessageChannel extends Channel
A Discord channel that can utilize messages.
  • Method Details

    • getLastMessageId

      default Optional<Snowflake> getLastMessageId()
      Gets the ID of the last message sent in this channel, if present.
      Returns:
      The ID of the last message sent in this channel, if present.
    • getLastMessage

      default Mono<Message> getLastMessage()
      Requests to retrieve the last message sent in this channel, if present.
      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

      default Mono<Message> getLastMessage(EntityRetrievalStrategy retrievalStrategy)
      Requests to retrieve the last message sent in this channel, if present, using the given retrieval strategy.
      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.
    • getLastPinTimestamp

      default Optional<Instant> getLastPinTimestamp()
      Gets when the last pinned message was pinned, if present.
      Returns:
      When the last pinned message was pinned, if present.
    • createMessage

      @Deprecated default Mono<Message> createMessage(Consumer<? super LegacyMessageCreateSpec> spec)
      Deprecated.
      use createMessage(MessageCreateSpec) or createMessage(String) which offer an immutable approach to build specs
      Requests to create a message.
      Parameters:
      spec - A Consumer that provides a "blank" LegacyMessageCreateSpec to be operated on.
      Returns:
      A Mono where, upon successful completion, emits the created Message. If an error is received, it is emitted through the Mono.
    • createMessage

      default Mono<Message> createMessage(discord4j.core.spec.MessageCreateSpec spec)
      Requests to create a message.
      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()
    • createMessage

      default discord4j.core.spec.MessageCreateMono createMessage(String message)
      Requests to create a message with a content. Other properties specifying how to create the message can be set via the withXxx methods of the returned MessageCreateMono.
      Parameters:
      message - A string message to populate the message with.
      Returns:
      A MessageCreateMono where, upon successful completion, emits the created Message. If an error is received, it is emitted through the MessageCreateMono.
      See Also:
    • createMessage

      default discord4j.core.spec.MessageCreateMono createMessage(discord4j.core.spec.EmbedCreateSpec... embeds)
      Requests to create a message with embeds. Other properties specifying how to create the message can be set via the withXxx methods of the returned MessageCreateMono.
      Parameters:
      embeds - immutable objects that specify how to create the embeds
      Returns:
      A MessageCreateMono where, upon successful completion, emits the created Message. If an error is received, it is emitted through the MessageCreateMono.
      See Also:
    • createEmbed

      @Deprecated default Mono<Message> createEmbed(Consumer<? super LegacyEmbedCreateSpec> spec)
      Deprecated.
      use createEmbed(EmbedCreateSpec) which offers an immutable approach to build specs
      Requests to create a message with an embed.
      Parameters:
      spec - A Consumer that provides a "blank" LegacyEmbedCreateSpec to be operated on.
      Returns:
      A Mono where, upon successful completion, emits the created Message. If an error is received, it is emitted through the Mono.
    • createEmbed

      @Deprecated default discord4j.core.spec.MessageCreateMono createEmbed(discord4j.core.spec.EmbedCreateSpec embed)
      Requests to create a message with an embed. Other properties specifying how to create the message can be set via the withXxx methods of the returned MessageCreateMono.
      Parameters:
      embed - an immutable object that specifies how to create the embed
      Returns:
      A MessageCreateMono where, upon successful completion, emits the created Message. If an error is received, it is emitted through the MessageCreateMono.
      See Also:
    • type

      default Mono<Void> type()
      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.
      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

      default Flux<Long> typeUntil(Publisher<?> until)
      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"))
       
       
      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.
      Implementation Note:
      The default implementation actually sends a typing request every 8 seconds so it appears continuous.
    • getMessagesBefore

      default Flux<Message> getMessagesBefore(Snowflake messageId)
      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)

      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

      default Flux<Message> getMessagesAfter(Snowflake messageId)
      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)

      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

      default Mono<Message> getMessageById(Snowflake id)
      Requests to retrieve the message as represented by the supplied ID.
      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

      default Mono<Message> getMessageById(Snowflake id, EntityRetrievalStrategy retrievalStrategy)
      Requests to retrieve the message as represented by the supplied ID, using the given retrieval strategy.
      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

      default Flux<Message> getPinnedMessages()
      Requests 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.