mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-03 08:35:53 +00:00
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:
@ -71,7 +71,7 @@ if TYPE_CHECKING:
|
||||
from ..emoji import Emoji
|
||||
from ..channel import VoiceChannel
|
||||
from ..abc import Snowflake
|
||||
from ..ui.view import View
|
||||
from ..ui.view import BaseView, View, LayoutView
|
||||
from ..poll import Poll
|
||||
import datetime
|
||||
from ..types.webhook import (
|
||||
@ -552,7 +552,7 @@ def interaction_message_response_params(
|
||||
embed: Optional[Embed] = MISSING,
|
||||
embeds: Sequence[Embed] = MISSING,
|
||||
attachments: Sequence[Union[Attachment, File]] = MISSING,
|
||||
view: Optional[View] = MISSING,
|
||||
view: Optional[BaseView] = MISSING,
|
||||
allowed_mentions: Optional[AllowedMentions] = MISSING,
|
||||
previous_allowed_mentions: Optional[AllowedMentions] = None,
|
||||
poll: Poll = MISSING,
|
||||
@ -592,6 +592,13 @@ def interaction_message_response_params(
|
||||
if view is not MISSING:
|
||||
if view is not None:
|
||||
data['components'] = view.to_components()
|
||||
|
||||
if view.has_components_v2():
|
||||
if flags is not MISSING:
|
||||
flags.components_v2 = True
|
||||
else:
|
||||
flags = MessageFlags(components_v2=True)
|
||||
|
||||
else:
|
||||
data['components'] = []
|
||||
|
||||
@ -802,7 +809,7 @@ class WebhookMessage(Message):
|
||||
embeds: Sequence[Embed] = MISSING,
|
||||
embed: Optional[Embed] = MISSING,
|
||||
attachments: Sequence[Union[Attachment, File]] = MISSING,
|
||||
view: Optional[View] = MISSING,
|
||||
view: Optional[BaseView] = MISSING,
|
||||
allowed_mentions: Optional[AllowedMentions] = None,
|
||||
) -> WebhookMessage:
|
||||
"""|coro|
|
||||
@ -1598,6 +1605,46 @@ class Webhook(BaseWebhook):
|
||||
# state is artificial
|
||||
return WebhookMessage(data=data, state=state, channel=channel) # type: ignore
|
||||
|
||||
@overload
|
||||
async def send(
|
||||
self,
|
||||
*,
|
||||
username: str = MISSING,
|
||||
avatar_url: Any = MISSING,
|
||||
ephemeral: bool = 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,
|
||||
) -> WebhookMessage:
|
||||
...
|
||||
|
||||
@overload
|
||||
async def send(
|
||||
self,
|
||||
*,
|
||||
username: str = MISSING,
|
||||
avatar_url: Any = MISSING,
|
||||
ephemeral: bool = 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
|
||||
async def send(
|
||||
self,
|
||||
@ -1661,7 +1708,7 @@ class Webhook(BaseWebhook):
|
||||
embed: Embed = MISSING,
|
||||
embeds: Sequence[Embed] = MISSING,
|
||||
allowed_mentions: AllowedMentions = MISSING,
|
||||
view: View = MISSING,
|
||||
view: BaseView = MISSING,
|
||||
thread: Snowflake = MISSING,
|
||||
thread_name: str = MISSING,
|
||||
wait: bool = False,
|
||||
@ -1727,7 +1774,7 @@ class Webhook(BaseWebhook):
|
||||
Controls the mentions being processed in this message.
|
||||
|
||||
.. versionadded:: 1.4
|
||||
view: :class:`discord.ui.View`
|
||||
view: Union[:class:`discord.ui.View`, :class:`discord.ui.LayoutView`]
|
||||
The view to send with the message. If the webhook is partial or
|
||||
is not managed by the library, then you can only send URL buttons.
|
||||
Otherwise, you can send views with any type of components.
|
||||
@ -1931,6 +1978,33 @@ class Webhook(BaseWebhook):
|
||||
)
|
||||
return self._create_message(data, thread=thread)
|
||||
|
||||
@overload
|
||||
async def edit_message(
|
||||
self,
|
||||
message_id: int,
|
||||
*,
|
||||
attachments: Sequence[Union[Attachment, File]] = ...,
|
||||
view: LayoutView,
|
||||
allowed_mentions: Optional[AllowedMentions] = ...,
|
||||
thread: Snowflake = ...,
|
||||
) -> WebhookMessage:
|
||||
...
|
||||
|
||||
@overload
|
||||
async 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 = ...,
|
||||
) -> WebhookMessage:
|
||||
...
|
||||
|
||||
async def edit_message(
|
||||
self,
|
||||
message_id: int,
|
||||
@ -1939,7 +2013,7 @@ class Webhook(BaseWebhook):
|
||||
embeds: Sequence[Embed] = MISSING,
|
||||
embed: Optional[Embed] = MISSING,
|
||||
attachments: Sequence[Union[Attachment, File]] = MISSING,
|
||||
view: Optional[View] = MISSING,
|
||||
view: Optional[BaseView] = MISSING,
|
||||
allowed_mentions: Optional[AllowedMentions] = None,
|
||||
thread: Snowflake = MISSING,
|
||||
) -> WebhookMessage:
|
||||
@ -1978,11 +2052,17 @@ class Webhook(BaseWebhook):
|
||||
allowed_mentions: :class:`AllowedMentions`
|
||||
Controls the mentions being processed in this message.
|
||||
See :meth:`.abc.Messageable.send` for more information.
|
||||
view: Optional[:class:`~discord.ui.View`]
|
||||
view: Optional[Union[:class:`~discord.ui.View`, :class:`~discord.ui.LayoutView`]]
|
||||
The updated view to update this message with. If ``None`` is passed then
|
||||
the view is removed. The webhook must have state attached, similar to
|
||||
:meth:`send`.
|
||||
|
||||
.. note::
|
||||
|
||||
To update the message to add a :class:`~discord.ui.LayoutView`, you
|
||||
must explicitly set the ``content``, ``embed``, ``embeds``, and
|
||||
``attachments`` parameters to either ``None`` or an empty array, as appropriate.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
thread: :class:`~discord.abc.Snowflake`
|
||||
The thread the webhook message belongs to.
|
||||
@ -2046,7 +2126,7 @@ class Webhook(BaseWebhook):
|
||||
)
|
||||
|
||||
message = self._create_message(data, thread=thread)
|
||||
if view and not view.is_finished():
|
||||
if view and not view.is_finished() and view.is_dispatchable():
|
||||
self._state.store_view(view, message_id)
|
||||
return message
|
||||
|
||||
|
Reference in New Issue
Block a user