View Source Nostrum.Struct.Message.Poll (Nostrum v0.9.1)

Struct representing a poll in a Discord chat.

There are various helper methods on this structure to create new poll, see create_poll/2 and put_answer/2 & put_answer/3 for code samples.

Summary

Types

Whether the poll allows selection of multiple answers

List of potential answers for the poll

Duration of poll in hours

Expiry time of the poll

Layout type for the poll, currently only 1 (DEFAULT) is supported here.

Question for the poll

Result counts of a poll that has been voted on.

t()

Functions

Create a new poll struct.

Add an answer to the provided poll.

Types

Link to this type

allow_multiselect()

View Source (since 0.9.0)
@type allow_multiselect() :: boolean()

Whether the poll allows selection of multiple answers

Link to this type

answers()

View Source (since 0.9.0)
@type answers() :: [Nostrum.Struct.Message.Poll.Answer.t()]

List of potential answers for the poll

Link to this type

duration()

View Source (since 0.9.0)
@type duration() :: integer() | nil

Duration of poll in hours

Link to this type

expiry()

View Source (since 0.9.0)
@type expiry() :: DateTime.t() | nil

Expiry time of the poll

Link to this type

layout_type()

View Source (since 0.9.0)
@type layout_type() :: 1 | nil

Layout type for the poll, currently only 1 (DEFAULT) is supported here.

If set to nil, the value will default to 1 at the Discord API.

Link to this type

question()

View Source (since 0.9.0)

Question for the poll

Link to this type

results()

View Source (since 0.9.0)
@type results() :: Nostrum.Struct.Message.Poll.Results.t() | nil

Result counts of a poll that has been voted on.

This field is only present for poll objects received over the gateway or Discord API.

As mentioned in the Nostrum.Struct.Message.Poll.Results documentation, if an answer has not been voted on it will not be in this object.

@type t() :: %Nostrum.Struct.Message.Poll{
  allow_multiselect: allow_multiselect(),
  answers: answers(),
  duration: duration(),
  expiry: expiry(),
  layout_type: layout_type(),
  question: question(),
  results: results()
}

Functions

Link to this function

create_poll(question_text, list)

View Source (since 0.9.0)
@spec create_poll(String.t(),
  duration: duration(),
  allow_multiselect: allow_multiselect()
) :: t()
@spec create_poll(String.t(),
  duration: duration(),
  allow_multiselect: allow_multiselect(),
  answers: [Nostrum.Struct.Message.Poll.Answer.t()]
) :: t()

Create a new poll struct.

Use Nostrum.Api.create_message to send it once you've populated it.

Accepts a question_text parameter which is the string to use as the poll title.

Keyword arguments:

  • duration: duration (in hours) the poll should be open for
  • allow_multiselect: whether users should be able to select multiple answers

You can also pass an answers key with answers, though put_answer/2 and put_answer/3 are advised.

Examples

poll = Poll.create_poll("Do you enjoy pineapple on pizza?", duration: 2, allow_multiselect: false)
        |> Poll.put_answer("Yes!", default_emoji: "\u2705") # check mark emoji
        |> Poll.put_answer("No!", default_emoji: "\u274C") # cross emoji

Api.create_message(channel_id, poll: poll)
Link to this function

put_answer(poll, answer)

View Source (since 0.9.0)
@spec put_answer(t(), String.t()) :: t()

Add an answer to the provided poll.

See create_poll/2 for a code sample of this function.

Takes a required "answer" text field, as well as either of the optional arguments:

  • custom_emoji: An integer representing the snowflake of an emoji to display with the option
  • default_emoji: A default platform emoji represented as a unicode character
Link to this function

put_answer(poll, answer, list)

View Source (since 0.9.0)
@spec put_answer(t(), String.t(), [{:custom_emoji, Nostrum.Snowflake.t()}]) :: t()
@spec put_answer(t(), String.t(), [{:default_emoji, String.t()}]) :: t()