mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +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:
@ -27,7 +27,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any, Dict, Optional, Generic, TYPE_CHECKING, Sequence, Tuple, Union, List
|
||||
from typing import Any, Dict, Optional, Generic, TYPE_CHECKING, Sequence, Tuple, Union, List, overload
|
||||
import asyncio
|
||||
import datetime
|
||||
|
||||
@ -76,7 +76,7 @@ if TYPE_CHECKING:
|
||||
from .mentions import AllowedMentions
|
||||
from aiohttp import ClientSession
|
||||
from .embeds import Embed
|
||||
from .ui.view import View
|
||||
from .ui.view import BaseView, View, LayoutView
|
||||
from .app_commands.models import Choice, ChoiceT
|
||||
from .ui.modal import Modal
|
||||
from .channel import VoiceChannel, StageChannel, TextChannel, ForumChannel, CategoryChannel, DMChannel, GroupChannel
|
||||
@ -482,7 +482,7 @@ class Interaction(Generic[ClientT]):
|
||||
embeds: Sequence[Embed] = MISSING,
|
||||
embed: Optional[Embed] = MISSING,
|
||||
attachments: Sequence[Union[Attachment, File]] = MISSING,
|
||||
view: Optional[View] = MISSING,
|
||||
view: Optional[Union[View, LayoutView]] = MISSING,
|
||||
allowed_mentions: Optional[AllowedMentions] = None,
|
||||
poll: Poll = MISSING,
|
||||
) -> InteractionMessage:
|
||||
@ -516,9 +516,15 @@ class Interaction(Generic[ClientT]):
|
||||
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.
|
||||
|
||||
.. note::
|
||||
|
||||
If you want to update the message to have a :class:`~discord.ui.LayoutView`, you must
|
||||
explicitly set the ``content``, ``embed``, ``embeds``, and ``attachments`` parameters to
|
||||
``None`` if the previous message had any.
|
||||
poll: :class:`Poll`
|
||||
The poll to create when editing the message.
|
||||
|
||||
@ -574,7 +580,7 @@ class Interaction(Generic[ClientT]):
|
||||
# The message channel types should always match
|
||||
state = _InteractionMessageState(self, self._state)
|
||||
message = InteractionMessage(state=state, channel=self.channel, data=data) # type: ignore
|
||||
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, interaction_id=self.id)
|
||||
return message
|
||||
|
||||
@ -898,6 +904,22 @@ class InteractionResponse(Generic[ClientT]):
|
||||
)
|
||||
self._response_type = InteractionResponseType.pong
|
||||
|
||||
@overload
|
||||
async def send_message(
|
||||
self,
|
||||
*,
|
||||
file: File = MISSING,
|
||||
files: Sequence[File] = MISSING,
|
||||
view: LayoutView,
|
||||
ephemeral: bool = False,
|
||||
allowed_mentions: AllowedMentions = MISSING,
|
||||
suppress_embeds: bool = False,
|
||||
silent: bool = False,
|
||||
delete_after: Optional[float] = None,
|
||||
) -> InteractionCallbackResponse[ClientT]:
|
||||
...
|
||||
|
||||
@overload
|
||||
async def send_message(
|
||||
self,
|
||||
content: Optional[Any] = None,
|
||||
@ -914,6 +936,25 @@ class InteractionResponse(Generic[ClientT]):
|
||||
silent: bool = False,
|
||||
delete_after: Optional[float] = None,
|
||||
poll: Poll = MISSING,
|
||||
) -> InteractionCallbackResponse[ClientT]:
|
||||
...
|
||||
|
||||
async def send_message(
|
||||
self,
|
||||
content: Optional[Any] = None,
|
||||
*,
|
||||
embed: Embed = MISSING,
|
||||
embeds: Sequence[Embed] = MISSING,
|
||||
file: File = MISSING,
|
||||
files: Sequence[File] = MISSING,
|
||||
view: BaseView = MISSING,
|
||||
tts: bool = False,
|
||||
ephemeral: bool = False,
|
||||
allowed_mentions: AllowedMentions = MISSING,
|
||||
suppress_embeds: bool = False,
|
||||
silent: bool = False,
|
||||
delete_after: Optional[float] = None,
|
||||
poll: Poll = MISSING,
|
||||
) -> InteractionCallbackResponse[ClientT]:
|
||||
"""|coro|
|
||||
|
||||
@ -938,7 +979,7 @@ class InteractionResponse(Generic[ClientT]):
|
||||
A list of files to upload. Must be a maximum of 10.
|
||||
tts: :class:`bool`
|
||||
Indicates if the message should be sent using text-to-speech.
|
||||
view: :class:`discord.ui.View`
|
||||
view: Union[:class:`discord.ui.View`, :class:`discord.ui.LayoutView`]
|
||||
The view to send with the message.
|
||||
ephemeral: :class:`bool`
|
||||
Indicates if the message should only be visible to the user who started the interaction.
|
||||
@ -1055,7 +1096,7 @@ class InteractionResponse(Generic[ClientT]):
|
||||
embed: Optional[Embed] = MISSING,
|
||||
embeds: Sequence[Embed] = MISSING,
|
||||
attachments: Sequence[Union[Attachment, File]] = MISSING,
|
||||
view: Optional[View] = MISSING,
|
||||
view: Optional[Union[View, LayoutView]] = MISSING,
|
||||
allowed_mentions: Optional[AllowedMentions] = MISSING,
|
||||
delete_after: Optional[float] = None,
|
||||
suppress_embeds: bool = MISSING,
|
||||
@ -1085,9 +1126,15 @@ class InteractionResponse(Generic[ClientT]):
|
||||
|
||||
New files will always appear after current attachments.
|
||||
|
||||
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.
|
||||
|
||||
.. 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.
|
||||
allowed_mentions: Optional[:class:`~discord.AllowedMentions`]
|
||||
Controls the mentions being processed in this message. See :meth:`.Message.edit`
|
||||
for more information.
|
||||
@ -1169,7 +1216,7 @@ class InteractionResponse(Generic[ClientT]):
|
||||
params=params,
|
||||
)
|
||||
|
||||
if view and not view.is_finished():
|
||||
if view and not view.is_finished() and view.is_dispatchable():
|
||||
state.store_view(view, message_id, interaction_id=original_interaction_id)
|
||||
|
||||
self._response_type = InteractionResponseType.message_update
|
||||
@ -1382,6 +1429,18 @@ class InteractionMessage(Message):
|
||||
__slots__ = ()
|
||||
_state: _InteractionMessageState
|
||||
|
||||
@overload
|
||||
async def edit(
|
||||
self,
|
||||
*,
|
||||
attachments: Sequence[Union[Attachment, File]] = MISSING,
|
||||
view: LayoutView,
|
||||
allowed_mentions: Optional[AllowedMentions] = None,
|
||||
delete_after: Optional[float] = None,
|
||||
) -> InteractionMessage:
|
||||
...
|
||||
|
||||
@overload
|
||||
async def edit(
|
||||
self,
|
||||
*,
|
||||
@ -1393,6 +1452,20 @@ class InteractionMessage(Message):
|
||||
allowed_mentions: Optional[AllowedMentions] = None,
|
||||
delete_after: Optional[float] = None,
|
||||
poll: Poll = MISSING,
|
||||
) -> InteractionMessage:
|
||||
...
|
||||
|
||||
async def edit(
|
||||
self,
|
||||
*,
|
||||
content: Optional[str] = MISSING,
|
||||
embeds: Sequence[Embed] = MISSING,
|
||||
embed: Optional[Embed] = MISSING,
|
||||
attachments: Sequence[Union[Attachment, File]] = MISSING,
|
||||
view: Optional[Union[View, LayoutView]] = MISSING,
|
||||
allowed_mentions: Optional[AllowedMentions] = None,
|
||||
delete_after: Optional[float] = None,
|
||||
poll: Poll = MISSING,
|
||||
) -> InteractionMessage:
|
||||
"""|coro|
|
||||
|
||||
@ -1418,9 +1491,15 @@ class InteractionMessage(Message):
|
||||
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.
|
||||
|
||||
.. note::
|
||||
|
||||
If you want to update the message to have a :class:`~discord.ui.LayoutView`, you must
|
||||
explicitly set the ``content``, ``embed``, ``embeds``, and ``attachments`` parameters to
|
||||
``None`` if the previous message had any.
|
||||
delete_after: Optional[:class:`float`]
|
||||
If provided, the number of seconds to wait in the background
|
||||
before deleting the message we just sent. If the deletion fails,
|
||||
|
Reference in New Issue
Block a user