-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Polls #9759
Add support for Polls #9759
Conversation
Is there documentation or an announcement surrounding this feature? |
Not yet, but it is getting a pop-up saying you to try it, though you cannot send them (you get a 403: Forbidden). |
Added the different layout types. Co-authored-by: owocado <[email protected]>
Thanks for the PR. Discord has asked that I do not implement this yet and will give me private documentation when the time comes. |
…ged user in parse_message_poll_vote to be able to be a Member
I am applying the suggested changes, most of them are already implemented and I forgot to add a comment and resolve the conversations, lol sorry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the CI failures.
discord/http.py
Outdated
if len(poll) == 0 or len(poll) > 10: | ||
raise ValueError('Poll must contain between 1 and 10 answers') | ||
if poll._hours_duration < 1 or poll._hours_duration > 168: | ||
raise ValueError('Polls duration must be between 1 hour and 7 days') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, the library delegates this stuff to the server side since it's the source of truth. It only validates when the trade-off for user experience is better (e.g. discord.ui
). This is not true for polls to me.
docs/api.rst
Outdated
@@ -1442,6 +1442,71 @@ Voice | |||
:param after: The voice state after the changes. | |||
:type after: :class:`VoiceState` | |||
|
|||
Polls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These events are alphabetically sorted, P comes before V not after. The English alphabet is ABCDEFGHIJKLMNOPQRSTUVWXYZ
docs/api.rst
Outdated
Called when a :class:`Message`\'s attached :class:`Poll` gets a new vote. If any of ``user`` or ``message`` | ||
are not cached this event will not be called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Called when a :class:`Message`\'s attached :class:`Poll` gets a new vote. If any of ``user`` or ``message`` | |
are not cached this event will not be called. | |
Called when a :class:`Message`\'s attached :class:`Poll` gets a new vote. If the ``user`` or ``message`` | |
are not cached then this event will not be called. |
docs/api.rst
Outdated
|
||
.. note:: | ||
|
||
If the poll allows multiselect and the user votes for more than one answer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the poll allows multiselect and the user votes for more than one answer | |
If the poll allows multiple answers and the user votes for more than one answer |
docs/api.rst
Outdated
|
||
:param user: The user that voted for the message's poll. | ||
:type user: Union[:class:`User`, :class:`Member`] | ||
:param answer: The answer the user voted to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param answer: The answer the user voted to. | |
:param answer: The answer the user voted on. |
docs/api.rst
Outdated
.. function:: on_poll_vote_remove(user, answer) | ||
|
||
Called when a :class:`Message`\'s attached :class:`Poll` has lost a vote. If any of ``user`` or ``message`` | ||
are not cached this event will not be called. | ||
|
||
This requires :attr:`Intents.message_content` and :attr:`Intents.polls` to be enabled. | ||
|
||
.. note:: | ||
|
||
If the poll allows multiselect and the user removes more than one vote | ||
this event will be called as many times as votes removed. | ||
|
||
.. versionadded:: 2.4 | ||
|
||
:param user: The user that removed their vote from the message's poll. | ||
:type user: Union[:class:`User`, :class:`Member`] | ||
:param answer: The answer the user removed the vote from. | ||
:type answer: :class:`PollAnswer` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should collapse this with the one above, similar to the other events.
Parse str input for emoji into partial emoji
/ PollAnswer.emoji it is just a 'return self.media.emoji' / PollMedia now transforms a str into a PartialEmoji, leaving the PollMedia.emoji as Union[PartialEmoji, Emoji] / PollAnswer now updates the self_voted attr in _handle_vote / (idk if i did in an early commit) Made Poll._answers a mapping of {answer_id: answer} instead of a list / ('') Raise ClientException instead of RuntimeError -- Maybe I am forgetting some changes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one final nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Summary
Adds support for Polls.
Related PRs:
Additions:
Poll
,PollAnswer
andPollMedia
objects.PollLayoutType
enumon_poll_vote_add
/remove
events.poll
attribute toMessage
poll
kwarg inMessageable.send
Checklist