D++ (DPP)
C++ Discord API Bot Library
dpp::poll Struct Reference

Represents a poll. More...

#include <message.h>

+ Collaboration diagram for dpp::poll:

Public Member Functions

pollset_question (std::string_view text)
 Set the question for this poll. More...
 
pollset_duration (uint32_t hours) noexcept
 Set the duration of the poll in hours. More...
 
pollset_allow_multiselect (bool allow) noexcept
 Set if the poll should allow multi-selecting. More...
 
polladd_answer (const poll_media &media)
 Add an answer to this poll. More...
 
polladd_answer (std::string_view text, snowflake emoji_id=0, bool is_animated=false)
 Add an answer to this poll. More...
 
polladd_answer (std::string_view text, std::string_view emoji)
 Add an answer to this poll. More...
 
polladd_answer (std::string_view text, const emoji &e)
 Add an answer to this poll. More...
 
const std::string & get_question_text () const noexcept
 Helper to get the question text. More...
 
const poll_mediafind_answer (uint32_t id) const noexcept
 Helper to find an answer by ID. More...
 
std::optional< uint32_t > get_vote_count (uint32_t answer_id) const noexcept
 Helper to find the vote count in the results. More...
 

Public Attributes

poll_media question {}
 Poll question. At the time of writing only the text field is supported by Discord. More...
 
std::map< uint32_t, poll_answeranswers {}
 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_resultsresults {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...
 

Detailed Description

Member Function Documentation

◆ add_answer() [1/4]

poll & dpp::poll::add_answer ( const poll_media media)

Add an answer to this poll.

Note
At the time of writing this, a poll can have up to 10 answers
Parameters
mediaData of the answer
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
textText for the answer
eOptional 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
textText for the answer
emoji_idOptional emoji
is_animatedWhether 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
textText for the answer
emojiOptional 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
idID to find
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_idID 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
allowShould 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
hoursDuration 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
textText for the question
Returns
self for method chaining

Member Data Documentation

◆ allow_multiselect

bool dpp::poll::allow_multiselect {false}

Whether a user can select multiple answers.

◆ answers

std::map<uint32_t, poll_answer> dpp::poll::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

poll_layout_type dpp::poll::layout_type {pl_default}

Layout type of the poll. Defaults to, well, pl_default.

See also
poll_layout_type

◆ question

poll_media dpp::poll::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
D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0