mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-03 08:35:53 +00:00
Add support for Polls
Co-authored-by: owocado <24418520+owocado@users.noreply.github.com> Co-authored-by: Josh <8677174+bijij@users.noreply.github.com> Co-authored-by: Trevor Flahardy <75498301+trevorflahardy@users.noreply.github.com>
This commit is contained in:
@ -72,6 +72,7 @@ if TYPE_CHECKING:
|
||||
from ..channel import VoiceChannel
|
||||
from ..abc import Snowflake
|
||||
from ..ui.view import View
|
||||
from ..poll import Poll
|
||||
import datetime
|
||||
from ..types.webhook import (
|
||||
Webhook as WebhookPayload,
|
||||
@ -541,6 +542,7 @@ def interaction_message_response_params(
|
||||
view: Optional[View] = MISSING,
|
||||
allowed_mentions: Optional[AllowedMentions] = MISSING,
|
||||
previous_allowed_mentions: Optional[AllowedMentions] = None,
|
||||
poll: Poll = MISSING,
|
||||
) -> MultipartParameters:
|
||||
if files is not MISSING and file is not MISSING:
|
||||
raise TypeError('Cannot mix file and files keyword arguments.')
|
||||
@ -608,6 +610,9 @@ def interaction_message_response_params(
|
||||
|
||||
data['attachments'] = attachments_payload
|
||||
|
||||
if poll is not MISSING:
|
||||
data['poll'] = poll._to_dict()
|
||||
|
||||
multipart = []
|
||||
if files:
|
||||
data = {'type': type, 'data': data}
|
||||
@ -1597,6 +1602,7 @@ class Webhook(BaseWebhook):
|
||||
suppress_embeds: bool = MISSING,
|
||||
silent: bool = MISSING,
|
||||
applied_tags: List[ForumTag] = MISSING,
|
||||
poll: Poll = MISSING,
|
||||
) -> WebhookMessage:
|
||||
...
|
||||
|
||||
@ -1621,6 +1627,7 @@ class Webhook(BaseWebhook):
|
||||
suppress_embeds: bool = MISSING,
|
||||
silent: bool = MISSING,
|
||||
applied_tags: List[ForumTag] = MISSING,
|
||||
poll: Poll = MISSING,
|
||||
) -> None:
|
||||
...
|
||||
|
||||
@ -1644,6 +1651,7 @@ class Webhook(BaseWebhook):
|
||||
suppress_embeds: bool = False,
|
||||
silent: bool = False,
|
||||
applied_tags: List[ForumTag] = MISSING,
|
||||
poll: Poll = MISSING,
|
||||
) -> Optional[WebhookMessage]:
|
||||
"""|coro|
|
||||
|
||||
@ -1734,6 +1742,15 @@ class Webhook(BaseWebhook):
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
poll: :class:`Poll`
|
||||
The poll to send with this message.
|
||||
|
||||
.. warning::
|
||||
|
||||
When sending a Poll via webhook, you cannot manually end it.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
Raises
|
||||
--------
|
||||
HTTPException
|
||||
@ -1811,6 +1828,7 @@ class Webhook(BaseWebhook):
|
||||
allowed_mentions=allowed_mentions,
|
||||
previous_allowed_mentions=previous_mentions,
|
||||
applied_tags=applied_tag_ids,
|
||||
poll=poll,
|
||||
) as params:
|
||||
adapter = async_context.get()
|
||||
thread_id: Optional[int] = None
|
||||
@ -1838,6 +1856,9 @@ class Webhook(BaseWebhook):
|
||||
message_id = None if msg is None else msg.id
|
||||
self._state.store_view(view, message_id)
|
||||
|
||||
if poll is not MISSING and msg:
|
||||
poll._update(msg)
|
||||
|
||||
return msg
|
||||
|
||||
async def fetch_message(self, id: int, /, *, thread: Snowflake = MISSING) -> WebhookMessage:
|
||||
|
Reference in New Issue
Block a user