Represents a poll.
More...
#include <message.h>
|
poll_media | question {} |
| Poll question. At the time of writing only the text field is supported by Discord. More...
|
|
std::map< uint32_t, poll_answer > | answers {} |
| List of answers of the poll. More...
|
|
double | expiry {24.0} |
| When retriving a poll from the API, this is the timestamp at which the poll will expire. When creating a poll, this is the number of hours the poll should be up for, up to 7 days (168 hours), and this field will be rounded. More...
|
|
bool | allow_multiselect {false} |
| Whether a user can select multiple answers. More...
|
|
poll_layout_type | layout_type {pl_default} |
| Layout type of the poll. Defaults to, well, pl_default. More...
|
|
std::optional< poll_results > | results {std::nullopt} |
| The (optional) results of the poll. This field may or may not be present, and its absence means "unknown results", not "no results". More...
|
|
◆ add_answer() [1/4]
Add an answer to this poll.
- Note
- At the time of writing this, a poll can have up to 10 answers
- Parameters
-
- Returns
- self for method chaining
◆ add_answer() [2/4]
poll & dpp::poll::add_answer |
( |
std::string_view |
text, |
|
|
const emoji & |
e |
|
) |
| |
Add an answer to this poll.
- Note
- At the time of writing this, a poll can have up to 10 answers
- Parameters
-
text | Text for the answer |
e | Optional emoji |
- Returns
- self for method chaining
◆ add_answer() [3/4]
poll & dpp::poll::add_answer |
( |
std::string_view |
text, |
|
|
snowflake |
emoji_id = 0 , |
|
|
bool |
is_animated = false |
|
) |
| |
Add an answer to this poll.
- Note
- At the time of writing this, a poll can have up to 10 answers
- Parameters
-
text | Text for the answer |
emoji_id | Optional emoji |
is_animated | Whether the emoji is animated |
- Returns
- self for method chaining
◆ add_answer() [4/4]
poll & dpp::poll::add_answer |
( |
std::string_view |
text, |
|
|
std::string_view |
emoji |
|
) |
| |
Add an answer to this poll.
- Note
- At the time of writing this, a poll can have up to 10 answers
- Parameters
-
text | Text for the answer |
emoji | Optional emoji |
- Returns
- self for method chaining
◆ find_answer()
const poll_media * dpp::poll::find_answer |
( |
uint32_t |
id | ) |
const |
|
noexcept |
Helper to find an answer by ID.
- Parameters
-
- Returns
- Pointer to the answer with the matching ID, or nullptr if not found
◆ get_question_text()
const std::string & dpp::poll::get_question_text |
( |
| ) |
const |
|
noexcept |
Helper to get the question text.
- Returns
- question.text
◆ get_vote_count()
std::optional< uint32_t > dpp::poll::get_vote_count |
( |
uint32_t |
answer_id | ) |
const |
|
noexcept |
Helper to find the vote count in the results.
- Parameters
-
answer_id | ID of the answer to find |
- Returns
- std::optional<uint32_t> Optional count of votes. An empty optional means Discord did not send the results, it does not mean 0. It can also mean the poll does not have an answer with this ID
- See also
- https://discord.com/developers/docs/resources/poll#poll-results-object
◆ set_allow_multiselect()
poll & dpp::poll::set_allow_multiselect |
( |
bool |
allow | ) |
|
|
noexcept |
Set if the poll should allow multi-selecting.
- Parameters
-
allow | Should allow multi-select? |
- Returns
- self for method chaining
◆ set_duration()
poll & dpp::poll::set_duration |
( |
uint32_t |
hours | ) |
|
|
noexcept |
Set the duration of the poll in hours.
- Parameters
-
hours | Duration of the poll in hours, max 7 days (168 hours) at the time of writing |
- Returns
- self for method chaining
◆ set_question()
poll & dpp::poll::set_question |
( |
std::string_view |
text | ) |
|
Set the question for this poll.
- Parameters
-
text | Text for the question |
- Returns
- self for method chaining
◆ allow_multiselect
bool dpp::poll::allow_multiselect {false} |
Whether a user can select multiple answers.
◆ answers
List of answers of the poll.
- Note
- At the time of writing this can contain up to 10 answers
- See also
- answer
◆ expiry
double dpp::poll::expiry {24.0} |
When retriving a poll from the API, this is the timestamp at which the poll will expire. When creating a poll, this is the number of hours the poll should be up for, up to 7 days (168 hours), and this field will be rounded.
◆ layout_type
Layout type of the poll. Defaults to, well, pl_default.
- See also
- poll_layout_type
◆ question
Poll question. At the time of writing only the text field is supported by Discord.
- See also
- media
◆ results
std::optional<poll_results> dpp::poll::results {std::nullopt} |
The (optional) results of the poll. This field may or may not be present, and its absence means "unknown results", not "no results".
- Note
- Quote from Discord: "The results field may be not present in certain responses where, as an implementation detail,
we do not fetch the poll results in our backend. This should be treated as "unknown results",
as opposed to "no results". You can keep using the results if you have previously received them through other means."
- See also
- https://discord.com/developers/docs/resources/poll#poll-results-object