Skip to content

Commit 418b287

Browse files
committed
Document polls.
Done: These are things that should have some semblence of stability. * Document model * Document gateway events * Document endpoints. * Abort errors. TODO: Things that are still in-flight might still change. - Gateway event for votes - currently it's still reactions intent but that will change. - Allowing message content (and other fields). - Allowing editing (of message content, not of poll)
1 parent 35a75ab commit 418b287

File tree

7 files changed

+182
-18
lines changed

7 files changed

+182
-18
lines changed

docs/interactions/Receiving_and_Responding.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ Not all message fields are currently supported.
239239
| flags? | integer | [message flags](#DOCS_RESOURCES_CHANNEL/message-object-message-flags) combined as a [bitfield](https://en.wikipedia.org/wiki/Bit_field) (only `SUPPRESS_EMBEDS`, `EPHEMERAL`, and `SUPPRESS_NOTIFICATIONS` can be set) |
240240
| components? | array of [components](#DOCS_INTERACTIONS_MESSAGE_COMPONENTS/) | message components |
241241
| attachments? \* | array of partial [attachment](#DOCS_RESOURCES_CHANNEL/attachment-object) objects | attachment objects with filename and description |
242+
| poll? | [poll](#DOCS_RESOURCES_POLL/poll-object) object | A poll! |
242243

243244
\* See [Uploading Files](#DOCS_REFERENCE/uploading-files) for details.
244245

docs/resources/Channel.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Represents a message sent in a channel within Discord.
264264
> Fields specific to the `MESSAGE_CREATE` and `MESSAGE_UPDATE` events are listed in the [Gateway documentation](#DOCS_TOPICS_GATEWAY_EVENTS/message-create).
265265
266266
> warn
267-
> `content`, `embeds`, `attachments`, and `components` require the [`MESSAGE_CONTENT` intent](#DOCS_TOPICS_GATEWAY/message-content-intent) to receive non-empty values.
267+
> `content`, `embeds`, `attachments`, `components`, and `poll` require the [`MESSAGE_CONTENT` intent](#DOCS_TOPICS_GATEWAY/message-content-intent) to receive non-empty values.
268268
269269
| Field | Type | Description |
270270
|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -300,6 +300,7 @@ Represents a message sent in a channel within Discord.
300300
| position? | integer | A generally increasing integer (there may be gaps or duplicates) that represents the approximate position of the message in a thread, it can be used to estimate the relative position of the message in a thread in company with `total_message_sent` on parent thread |
301301
| role_subscription_data? | [role subscription data](#DOCS_RESOURCES_CHANNEL/role-subscription-data-object) object | data of the role subscription purchase or renewal that prompted this ROLE_SUBSCRIPTION_PURCHASE message |
302302
| resolved? | [resolved](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/interaction-object-resolved-data-structure) data | data for users, members, channels, and roles in the message's [auto-populated select menus](#DOCS_INTERACTIONS_MESSAGE_COMPONENTS/select-menus) |
303+
| poll? | [poll](#DOCS_RESOURCES_POLL/poll-object) object | A poll! |
303304

304305

305306
\* The author object follows the structure of the user object, but is only a valid user in the case where the message is generated by a user or bot user. If the message is generated by a webhook, the author object corresponds to the webhook's id, username, and avatar. You can tell if a message is generated by a webhook by checking for the `webhook_id` on the message object.
@@ -1051,7 +1052,7 @@ Files must be attached using a `multipart/form-data` body as described in [Uploa
10511052
###### JSON/Form Params
10521053

10531054
> info
1054-
> When creating a message, apps must provide a value for **at least one of** `content`, `embeds`, `sticker_ids`, `components`, or `files[n]`.
1055+
> When creating a message, apps must provide a value for **at least one of** `content`, `embeds`, `sticker_ids`, `components`, `files[n]`, or `poll`.
10551056
10561057
| Field | Type | Description |
10571058
|--------------------|---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -1068,8 +1069,9 @@ Files must be attached using a `multipart/form-data` body as described in [Uploa
10681069
| attachments? | array of partial [attachment](#DOCS_RESOURCES_CHANNEL/attachment-object) objects | Attachment objects with filename and description. See [Uploading Files](#DOCS_REFERENCE/uploading-files |
10691070
| flags? | integer | [Message flags](#DOCS_RESOURCES_CHANNEL/message-object-message-flags) combined as a [bitfield](https://en.wikipedia.org/wiki/Bit_field) (only `SUPPRESS_EMBEDS` and `SUPPRESS_NOTIFICATIONS` can be set) |
10701071
| enforce_nonce? | boolean | If true and nonce is present, it will be checked for uniqueness in the past few minutes. If another message was created by the same author with the same nonce, that message will be returned and no new message will be created. |
1072+
| poll? | [poll](#DOCS_RESOURCES_POLL/poll-object) object | A poll! |
10711073

1072-
\* At least one of `content`, `embeds`, `sticker_ids`, `components`, or `files[n]` is required.
1074+
\* At least one of `content`, `embeds`, `sticker_ids`, `components`, `files[n]`, or `poll` is required.
10731075

10741076
###### Example Request Body (application/json)
10751077

@@ -1461,6 +1463,7 @@ Returns archived threads in the channel that are of [type](#DOCS_RESOURCES_CHANN
14611463
|---------|-----------|----------------------------------------------|
14621464
| before? | snowflake | returns threads before this id |
14631465
| limit? | integer | optional maximum number of threads to return |
1466+
`text` should always be non-null right now for both questions and answers, but please do not depend on that in the future.
14641467

14651468
###### Response Body
14661469

docs/resources/Poll.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Poll Resource
2+
3+
A poll is... well... a poll! It holds information about a poll!
4+
5+
![If you get it you get it](example-poll.png)
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

Comments
 (0)