diff options
| author | Rapptz <[email protected]> | 2021-05-30 06:10:58 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-05-30 06:10:58 -0400 |
| commit | c6f3ed1af49a5b3f35a22b48dbdab7d2340428cc (patch) | |
| tree | 6c5d7ea9c01f56212e0ea3cf829e56338de2d02e | |
| parent | Allow assigning Select.options to refresh the select menu (diff) | |
| download | discord.py-c6f3ed1af49a5b3f35a22b48dbdab7d2340428cc.tar.xz discord.py-c6f3ed1af49a5b3f35a22b48dbdab7d2340428cc.zip | |
Allow sending View with Interaction.response.send_message
This also allows for ephemeral views and listening to said views
| -rw-r--r-- | discord/interactions.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/discord/interactions.py b/discord/interactions.py index c68f7f86..9fd85e60 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -244,6 +244,7 @@ class InteractionResponse: *, embed: Embed = MISSING, embeds: List[Embed] = MISSING, + view: View = MISSING, tts: bool = False, ephemeral: bool = False, ) -> None: @@ -263,8 +264,12 @@ class InteractionResponse: ``embeds`` parameter. tts: :class:`bool` Indicates if the message should be sent using text-to-speech. + view: :class:`discord.ui.View` + 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. + If a view is sent with an ephemeral message and it has no timeout set then the timeout + is set to 15 minutes. Raises ------- @@ -299,6 +304,9 @@ class InteractionResponse: if ephemeral: payload['flags'] = 64 + if view is not MISSING: + payload['components'] = view.to_components() + parent = self._parent adapter = async_context.get() await adapter.create_interaction_response( @@ -308,6 +316,13 @@ class InteractionResponse: type=InteractionResponseType.channel_message.value, data=payload, ) + + if view is not MISSING: + if ephemeral and view.timeout is None: + view.timeout = 15 * 60.0 + + self._parent._state.store_view(view) + self._responded = True async def edit_message( |