Class MessagePollBuilder

java.lang.Object
net.dv8tion.jda.api.utils.messages.MessagePollBuilder

public class MessagePollBuilder extends Object
Builder for MessagePollData
See Also:
  • Constructor Details

  • Method Details

    • setLayout

      @Nonnull public MessagePollBuilder setLayout(@Nonnull MessagePoll.LayoutType layout)
      They poll layout.
      Parameters:
      layout - The layout
      Returns:
      The updated builder
      Throws:
      IllegalArgumentException - If null or UNKNOWN is provided
    • setTitle

      @Nonnull public MessagePollBuilder setTitle(@Nonnull String title)
      Change the title for this poll.
      Parameters:
      title - The poll title (up to MessagePoll.MAX_QUESTION_TEXT_LENGTH characters)
      Returns:
      The updated builder
      Throws:
      IllegalArgumentException - If the title is blank or longer than MessagePoll.MAX_QUESTION_TEXT_LENGTH characters
    • setDuration

      @Nonnull public MessagePollBuilder setDuration(@Nonnull Duration duration)
      Change the duration for this poll.
      Default: 1 day

      The poll will automatically expire after this duration.

      Parameters:
      duration - The duration of this poll (in hours resolution)
      Returns:
      The updated builder
      Throws:
      IllegalArgumentException - If the duration is null, less than 1 hour, or longer than 168L hours (7 days)
    • setDuration

      @Nonnull public MessagePollBuilder setDuration(long duration, @Nonnull TimeUnit unit)
      Change the duration for this poll.
      Default: 1 day

      The poll will automatically expire after this duration.

      Parameters:
      duration - The duration of this poll (in hours resolution)
      unit - The time unit for the duration
      Returns:
      The updated builder
      Throws:
      IllegalArgumentException - If the time unit is null or the duration is not between 1 and 168L hours (7 days) long
    • setMultiAnswer

      @Nonnull public MessagePollBuilder setMultiAnswer(boolean multiAnswer)
      Whether this poll allows selecting multiple answers.
      Default: false
      Parameters:
      multiAnswer - True, if this poll should allow multiple answers
      Returns:
      The updated builder
    • addAnswer

      @Nonnull public MessagePollBuilder addAnswer(@Nonnull String title)
      Add an answer to this poll.
      Parameters:
      title - The answer title
      Returns:
      The updated builder
      Throws:
      IllegalArgumentException - If the title is null, blank, or longer than 55 characters
    • addAnswer

      @Nonnull public MessagePollBuilder addAnswer(@Nonnull String title, @Nullable Emoji emoji)
      Add an answer to this poll.
      Parameters:
      title - The answer title
      emoji - Optional emoji to show next to the answer text
      Returns:
      The updated builder
      Throws:
      IllegalArgumentException - If the title is null, blank, or longer than 55 characters
    • build

      @Nonnull public MessagePollData build()
      Build the poll data.
      Returns:
      MessagePollData
      Throws:
      IllegalStateException - If no answers have been added to the builder