|
| 1 | +# Poll Resource |
| 2 | + |
| 3 | +A poll is... well... a poll! It holds information about a poll! |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +### Poll Object |
| 8 | + |
| 9 | +The poll object has a lot of levels and nested structures. It was also designed |
| 10 | +to support future extensibility, so some fields may appear to be more complex than |
| 11 | +necessary. |
| 12 | + |
| 13 | +The request and response models are closely aligned. So for the sake of brevity |
| 14 | +we will have common structure declarations instead of duplicating request and response structures. |
| 15 | + |
| 16 | +Fields marked by an \* are only sent as part of responses from Discord's API/Gateway. |
| 17 | + |
| 18 | +###### Poll Object Structure |
| 19 | + |
| 20 | +| Field | Type | Description | |
| 21 | +|-------------------|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------| |
| 22 | +| question | [Poll Media Object](#DOCS_RESOURCES_POLL/poll-media-object-poll-media-object-structure) | The question of the poll. Only `text` is supported. | |
| 23 | +| answers | List of [Poll Answer Objects](#DOCS_RESOURCES_POLL/poll-answer-object-poll-answer-object-structure) | Each of the answers available in the poll. | |
| 24 | +| expiry | IS08601 timestamp | The time when the poll ends. | |
| 25 | +| allow_multiselect | boolean | Whether a user can select multiple answers | |
| 26 | +| layout_type | integer | The [layout type](#DOCS_RESOURCES_POLL/layout-type) of the poll | |
| 27 | +| results\* | [Poll Results Object](#DOCS_RESOURCES_POLL/poll-results-object-poll-results-object-structure) | The results of the poll | |
| 28 | + |
| 29 | +### Layout Type |
| 30 | + |
| 31 | +We might have different layouts for polls in the future. |
| 32 | +For now though, this number will be 1. |
| 33 | + |
| 34 | +| Type | ID | Description | |
| 35 | +|---------|----|--------------------------------| |
| 36 | +| DEFAULT | 1 | The, uhm, default layout type. | |
| 37 | + |
| 38 | +### Poll Media Object |
| 39 | + |
| 40 | +The poll media object is a common object that backs both the question and answers. |
| 41 | +The intention is that it allows us to extensibly add new ways to display things in the future. |
| 42 | +For now, `question` only supports `text`, while answers can have an optional `emoji`. |
| 43 | + |
| 44 | +###### Poll Media Object Structure |
| 45 | + |
| 46 | +| Field | Type | Description | |
| 47 | +|--------|-----------------------------------------------------|------------------------| |
| 48 | +| text? | string | The text of the field | |
| 49 | +| emoji? | partial [emoji](#DOCS_RESOURCES_EMOJI/emoji-object) | The emoji of the field | |
| 50 | + |
| 51 | +`text` should always be non-null for both questions and answers, but please do not depend on that in the future. |
| 52 | + |
| 53 | +When creating a poll answer with an emoji, one only needs to send either the `id` (custom emoji) or `name` (default emoji) as the only field. |
| 54 | + |
| 55 | +### Poll Answer Object |
| 56 | + |
| 57 | +The `answer_id` is a number that labels each answer. |
| 58 | +As an implementation detail, it currently starts at 1 for the first answer and goes up sequentially. |
| 59 | +We recommend against depending on this sequence. |
| 60 | + |
| 61 | +###### Poll Answer Object Structure |
| 62 | + |
| 63 | +| Field | Type | Description | |
| 64 | +|-------------|-----------------------------------------------------------------------------------------|------------------------| |
| 65 | +| answer_id\* | integer | The ID of the answer | |
| 66 | +| poll_media | [Poll Media Object](#DOCS_RESOURCES_POLL/poll-media-object-poll-media-object-structure) | The data of the answer | |
| 67 | + |
| 68 | +### Poll Results Object |
| 69 | + |
| 70 | +In a nutshell, this contains the number of votes for each answer. |
| 71 | + |
| 72 | +Due to the intricacies of counting at scale, while a poll is in progress the results may not be perfectly accurate. |
| 73 | +They usually are accurate, and shouldn't deviate significantly -- it's just difficult to make guarantees. |
| 74 | + |
| 75 | +To compensate for this, after a poll is finished there is a background job which performs a final, accurate tally of votes. |
| 76 | +This tally has concluded once `is_finalized` is `true`. |
| 77 | + |
| 78 | +If `answer_counts` does not contain an entry for a particular answer, then there are no votes for that answer. |
| 79 | + |
| 80 | +###### Poll Results Object Structure |
| 81 | + |
| 82 | +| Field | Type | Description | |
| 83 | +|---------------|-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------| |
| 84 | +| is_finalized | boolean | Whether the votes have been precisely counted | |
| 85 | +| answer_counts | List of [Poll Answer Count Object](#DOCS_RESOURCES_POLL/poll-results-object-poll-answer-count-object-structure) | The counts for each answer | |
| 86 | + |
| 87 | +###### Poll Answer Count Object Structure |
| 88 | + |
| 89 | +| Field | Type | Description | |
| 90 | +|----------|---------|------------------------------------------------| |
| 91 | +| id | integer | The `answer_id` | |
| 92 | +| count | integer | The number of votes for this answer | |
| 93 | +| me_voted | boolean | Whether the current user voted for this answer | |
| 94 | + |
| 95 | +# Poll Endpoints |
| 96 | + |
| 97 | +For creating a poll, see [Create Message](#DOCS_RESOURCES_CHANNEL/create-message). After creation, the poll message cannot be editted. |
| 98 | + |
| 99 | +Apps are not allowed to vote on polls. No rights! :) |
| 100 | + |
| 101 | +## Get Answer Voters % GET /channels/{channel.id#DOCS_RESOURCES_CHANNEL/channel-object}/polls/{message.id#DOCS_RESOURCES_CHANNEL/message-object}/answers/{answer_id#DOCS_RESOURCES_POLL/poll-answer-object} |
| 102 | + |
| 103 | +Get a list of users that voted for this specific answer. |
| 104 | + |
| 105 | +###### Query String Params |
| 106 | + |
| 107 | +| Field | Type | Description | Default | |
| 108 | +|--------|-----------|---------------------------------------|---------| |
| 109 | +| after? | snowflake | Get users after this user ID | absent | |
| 110 | +| limit? | integer | Max number of users to return (1-100) | 25 | |
| 111 | + |
| 112 | +###### Response Body |
| 113 | + |
| 114 | +| Field | Type | Description | |
| 115 | +|-------|---------------------------------------------------|----------------------------------| |
| 116 | +| users | array of [user](#DOCS_RESOURCES_USER/user-object) | Users who created to this answer | |
| 117 | + |
| 118 | +## Expire Poll % POST /channels/{channel.id#DOCS_RESOURCES_CHANNEL/channel-object}/poll/{message.id#DOCS_RESOURCES_CHANNEL/message-object}/expire |
| 119 | + |
| 120 | +Immediately expires (i.e. ends) the poll. |
| 121 | + |
| 122 | +Returns a [message](#DOCS_RESOURCES_CHANNEL/message-object) object. Fires a [Message Update](#DOCS_TOPICS_GATEWAY_EVENTS/message-update) Gateway event. |
0 commit comments