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:
DA344
2024-05-10 12:14:12 +02:00
committed by GitHub
parent a1206dfde8
commit e43bd8692c
19 changed files with 1097 additions and 1 deletions

View File

@ -61,6 +61,7 @@ if TYPE_CHECKING:
from ..file import File
from ..embeds import Embed
from ..poll import Poll
from ..mentions import AllowedMentions
from ..message import Attachment
from ..abc import Snowflake
@ -872,6 +873,7 @@ class SyncWebhook(BaseWebhook):
suppress_embeds: bool = MISSING,
silent: bool = MISSING,
applied_tags: List[ForumTag] = MISSING,
poll: Poll = MISSING,
) -> SyncWebhookMessage:
...
@ -894,6 +896,7 @@ class SyncWebhook(BaseWebhook):
suppress_embeds: bool = MISSING,
silent: bool = MISSING,
applied_tags: List[ForumTag] = MISSING,
poll: Poll = MISSING,
) -> None:
...
@ -915,6 +918,7 @@ class SyncWebhook(BaseWebhook):
suppress_embeds: bool = False,
silent: bool = False,
applied_tags: List[ForumTag] = MISSING,
poll: Poll = MISSING,
) -> Optional[SyncWebhookMessage]:
"""Sends a message using the webhook.
@ -979,6 +983,14 @@ class SyncWebhook(BaseWebhook):
in the UI, but will not actually send a notification.
.. versionadded:: 2.2
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
--------
@ -1037,6 +1049,7 @@ class SyncWebhook(BaseWebhook):
previous_allowed_mentions=previous_mentions,
flags=flags,
applied_tags=applied_tag_ids,
poll=poll,
) as params:
adapter: WebhookAdapter = _get_webhook_adapter()
thread_id: Optional[int] = None
@ -1054,8 +1067,15 @@ class SyncWebhook(BaseWebhook):
wait=wait,
)
msg = None
if wait:
return self._create_message(data, thread=thread)
msg = self._create_message(data, thread=thread)
if poll is not MISSING and msg:
poll._update(msg)
return msg
def fetch_message(self, id: int, /, *, thread: Snowflake = MISSING) -> SyncWebhookMessage:
"""Retrieves a single :class:`~discord.SyncWebhookMessage` owned by this webhook.