| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::poll Struct Reference

Represents a poll. More...

`#include <message.h>`

Collaboration diagram for dpp::poll:
[legend]

## Public Member Functions

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

## Public Attributes

bool | allow_multiselect {false}
| Whether a user can select multiple answers.
std::map< uint32_t, poll_answer > | answers {}
| List of answers of the poll.
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.
poll_layout_type | layout_type {pl_default}
| Layout type of the poll. Defaults to, well, pl_default.
poll_media | question {}
| Poll question. At the time of writing only the text field is supported by Discord.
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".

## Detailed Description

Represents a poll.

See also
  https://discord.com/developers/docs/resources/poll

## 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

  media | Data 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

  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

nodiscard noexcept

Helper to find an answer by ID.

Parameters

  id | ID 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

nodiscard 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

nodiscard 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

## 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 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0