Represents a single answer option in a Discord poll.
This struct flattens text and emoji directly for a simpler API
instead of wrapping them in a separate media object.
Example
%EDA.Poll.Answer{
answer_id: 1,
text: "Option A",
emoji: %EDA.Emoji{id: nil, name: "👍"}
}
Summary
Functions
Parses a poll answer from a raw Discord API map.
Serializes an answer to the Discord API format.
Types
@type t() :: %EDA.Poll.Answer{ answer_id: integer() | nil, emoji: EDA.Emoji.t() | nil, text: String.t() }
Functions
Parses a poll answer from a raw Discord API map.
Extracts text and emoji from the nested "poll_media" object.
Examples
iex> EDA.Poll.Answer.from_raw(%{"answer_id" => 1, "poll_media" => %{"text" => "Yes", "emoji" => %{"name" => "👍"}}})
%EDA.Poll.Answer{answer_id: 1, text: "Yes", emoji: %EDA.Emoji{name: "👍"}}
iex> EDA.Poll.Answer.from_raw(%{"answer_id" => 2, "poll_media" => %{"text" => "No"}})
%EDA.Poll.Answer{answer_id: 2, text: "No", emoji: nil}
Serializes an answer to the Discord API format.
Wraps text and emoji inside a "poll_media" object as Discord expects.
Examples
iex> EDA.Poll.Answer.to_raw(%EDA.Poll.Answer{text: "Yes", emoji: %EDA.Emoji{name: "👍"}})
%{"poll_media" => %{"text" => "Yes", "emoji" => %{"name" => "👍"}}}
iex> EDA.Poll.Answer.to_raw(%EDA.Poll.Answer{text: "No"})
%{"poll_media" => %{"text" => "No"}}