Nostrum.Struct.Message.Poll (nostrum v0.11.0-dev)
View SourceStruct 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.
Types
@type allow_multiselect() :: boolean()
Whether the poll allows selection of multiple answers
@type answers() :: [Nostrum.Struct.Message.Poll.Answer.t()]
List of potential answers for the poll
@type duration() :: integer() | nil
Duration of poll in hours
@type expiry() :: DateTime.t() | nil
Expiry time of the poll
@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.
@type question() :: Nostrum.Struct.Message.Poll.MediaObject.t()
Question for the poll
@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
@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.Message.create/2
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 forallow_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
Nostrum.Api.Message.create(channel_id, poll: poll)
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 optiondefault_emoji
: A default platform emoji represented as a unicode character