mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-09-22 19:22:01 +03:00
feat(interactions): add respond() method
This commit is contained in:
parent
240025351d
commit
e6b4ffca6c
2 changed files with 44 additions and 0 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue