Class: Discordrb::Poll::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data/poll.rb

Overview

Builder for polls.

Instance Method Summary collapse

Constructor Details

#initialize(question:, layout: :default, duration: 24, multiselect: false) ⇒ Builder

Create a poll request object.

Parameters:

  • question (String)

    The question of the poll; between 1-55 characters.

  • layout (Integer, Symbol, nil) (defaults to: :default)

    The layout type of the poll; see LAYOUTS.

  • duration (Integer, Time, nil) (defaults to: 24)

    The number of hours before the poll expires.

  • multiselect (true, false, nil) (defaults to: false)

    Whether or not users can pick multiple answers.



333
334
335
336
337
338
339
# File 'lib/discordrb/data/poll.rb', line 333

def initialize(question:, layout: :default, duration: 24, multiselect: false)
  @layout = layout
  @answers = []
  @question = question
  @duration = duration || 24
  @multiselect = multiselect
end

Instance Method Details

#answer(text:, emoji: nil) ⇒ void Also known as: add_answer

This method returns an undefined value.

Add an answer to the poll builder.

Parameters:



345
346
347
348
349
# File 'lib/discordrb/data/poll.rb', line 345

def answer(text:, emoji: nil)
  emoji = Emoji.build_emoji_hash(emoji, prefix: false) if emoji

  @answers << { poll_media: { text: text, emoji: emoji }.compact }
end