Add support for components V2

Co-authored-by: Michael H <michael@michaelhall.tech>
Co-authored-by: Soheab <33902984+Soheab@users.noreply.github.com>
Co-authored-by: owocado <24418520+owocado@users.noreply.github.com>
Co-authored-by: Jay3332 <40323796+jay3332@users.noreply.github.com>
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
This commit is contained in:
DA344
2025-08-14 02:37:23 +02:00
committed by GitHub
parent 6ec2e5329b
commit 50caa3c82c
33 changed files with 4214 additions and 298 deletions

View File

@ -66,7 +66,7 @@ if TYPE_CHECKING:
from ..message import Attachment
from ..abc import Snowflake
from ..state import ConnectionState
from ..ui import View
from ..ui.view import BaseView, View, LayoutView
from ..types.webhook import (
Webhook as WebhookPayload,
)
@ -856,6 +856,44 @@ class SyncWebhook(BaseWebhook):
# state is artificial
return SyncWebhookMessage(data=data, state=state, channel=channel) # type: ignore
@overload
def send(
self,
*,
username: str = MISSING,
avatar_url: Any = MISSING,
file: File = MISSING,
files: Sequence[File] = MISSING,
allowed_mentions: AllowedMentions = MISSING,
view: LayoutView,
wait: Literal[True],
thread: Snowflake = MISSING,
thread_name: str = MISSING,
suppress_embeds: bool = MISSING,
silent: bool = MISSING,
applied_tags: List[ForumTag] = MISSING,
) -> SyncWebhookMessage:
...
@overload
def send(
self,
*,
username: str = MISSING,
avatar_url: Any = MISSING,
file: File = MISSING,
files: Sequence[File] = MISSING,
allowed_mentions: AllowedMentions = MISSING,
view: LayoutView,
wait: Literal[False] = ...,
thread: Snowflake = MISSING,
thread_name: str = MISSING,
suppress_embeds: bool = MISSING,
silent: bool = MISSING,
applied_tags: List[ForumTag] = MISSING,
) -> None:
...
@overload
def send(
self,
@ -876,6 +914,7 @@ class SyncWebhook(BaseWebhook):
silent: bool = MISSING,
applied_tags: List[ForumTag] = MISSING,
poll: Poll = MISSING,
view: View = MISSING,
) -> SyncWebhookMessage:
...
@ -899,6 +938,7 @@ class SyncWebhook(BaseWebhook):
silent: bool = MISSING,
applied_tags: List[ForumTag] = MISSING,
poll: Poll = MISSING,
view: View = MISSING,
) -> None:
...
@ -921,7 +961,7 @@ class SyncWebhook(BaseWebhook):
silent: bool = False,
applied_tags: List[ForumTag] = MISSING,
poll: Poll = MISSING,
view: View = MISSING,
view: BaseView = MISSING,
) -> Optional[SyncWebhookMessage]:
"""Sends a message using the webhook.
@ -994,8 +1034,8 @@ class SyncWebhook(BaseWebhook):
When sending a Poll via webhook, you cannot manually end it.
.. versionadded:: 2.4
view: :class:`~discord.ui.View`
The view to send with the message. This can only have URL buttons, which donnot
view: Union[:class:`~discord.ui.View`, :class:`~discord.ui.LayoutView`]
The view to send with the message. This can only have non-interactible items, which do not
require a state to be attached to it.
If you want to send a view with any component attached to it, check :meth:`Webhook.send`.
@ -1143,6 +1183,33 @@ class SyncWebhook(BaseWebhook):
)
return self._create_message(data, thread=thread)
@overload
def edit_message(
self,
message_id: int,
*,
attachments: Sequence[Union[Attachment, File]] = ...,
view: LayoutView,
allowed_mentions: Optional[AllowedMentions] = ...,
thread: Snowflake = ...,
) -> SyncWebhookMessage:
...
@overload
def edit_message(
self,
message_id: int,
*,
content: Optional[str] = ...,
embeds: Sequence[Embed] = ...,
embed: Optional[Embed] = ...,
attachments: Sequence[Union[Attachment, File]] = ...,
view: Optional[View] = ...,
allowed_mentions: Optional[AllowedMentions] = ...,
thread: Snowflake = ...,
) -> SyncWebhookMessage:
...
def edit_message(
self,
message_id: int,
@ -1151,6 +1218,7 @@ class SyncWebhook(BaseWebhook):
embeds: Sequence[Embed] = MISSING,
embed: Optional[Embed] = MISSING,
attachments: Sequence[Union[Attachment, File]] = MISSING,
view: Optional[BaseView] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
thread: Snowflake = MISSING,
) -> SyncWebhookMessage:
@ -1177,6 +1245,13 @@ class SyncWebhook(BaseWebhook):
then all attachments are removed.
.. versionadded:: 2.0
view: Optional[Union[:class:`~discord.ui.View`, :class:`~discord.ui.LayoutView`]]
The updated view to update this message with. This can only have non-interactible items, which do not
require a state to be attached to it. If ``None`` is passed then the view is removed.
If you want to edit a webhook message with any component attached to it, check :meth:`WebhookMessage.edit`.
.. versionadded:: 2.6
allowed_mentions: :class:`AllowedMentions`
Controls the mentions being processed in this message.
See :meth:`.abc.Messageable.send` for more information.