diff --git a/melisa/models/interactions/interactions.py b/melisa/models/interactions/interactions.py index c2e1ffb..cc5a2d3 100644 --- a/melisa/models/interactions/interactions.py +++ b/melisa/models/interactions/interactions.py @@ -78,6 +78,7 @@ class InteractionCallbackType(IntEnum): return self.value +@dataclass(repr=False) class InteractionResponse(APIModelBase): """Interaction Response @@ -88,6 +89,7 @@ class InteractionResponse(APIModelBase): data: Optional[Any] An optional response message """ + type: InteractionCallbackType data: Optional[Any] @@ -213,6 +215,18 @@ class Interaction(APIModelBase): return self + async def respond(self, response: InteractionResponse): + """ + Respond to an interaction. + + Parameters + ---------- + response: :class:`~melisa.models.interactions.interactions.InteractionResponse` + The response to send. + """ + + await self._client.rest.interaction_respond(self, response) + @dataclass(repr=False) class ResolvedData(APIModelBase): diff --git a/melisa/rest.py b/melisa/rest.py index efb7d69..aa75142 100644 --- a/melisa/rest.py +++ b/melisa/rest.py @@ -14,6 +14,7 @@ from .models.interactions.commands import ( _choose_command_type, ) from .models.interactions.i18n import LocalizedField +from .models.interactions.interactions import Interaction, InteractionResponse from .models.message import Embed, File, AllowedMentions, Message from .exceptions import EmbedFieldError from .core.http import HTTPClient @@ -1232,6 +1233,35 @@ class RESTApp: ) ] + async def interaction_respond( + self, interaction: Interaction, interaction_response: InteractionResponse + ): + """|coro| + + [**REST API**] Respond to an interaciton + + Parameters + ---------- + interaction: :class:`~melisa.models.interactions.interactions.Interaction` + Interaction to respond to + interaction_response: :class:`~melisa.models.interactions.interactions.InteractionResponse` + InteractionResponse`e`` + + Raises + ------- + HTTPException + The request to perform the action failed with other http exception. + ForbiddenError + You do not have proper permissions to do the actions required. + BadRequestError + You provided a wrong arguments + """ + + return await self._http.post( + f"/interactions/{interaction.id}/{interaction.token}/callback", + json=interaction_response.to_dict(), + ) + class CDNBuilder: """Can be used to build images