|
38 | 38 | from .object import Object
|
39 | 39 | from .permissions import Permissions
|
40 | 40 | from .user import User
|
41 |
| -from .webhook.async_ import Webhook, async_context, handle_message_parameters |
| 41 | +from .webhook.async_ import ( |
| 42 | + Webhook, |
| 43 | + WebhookMessage, |
| 44 | + async_context, |
| 45 | + handle_message_parameters, |
| 46 | +) |
42 | 47 |
|
43 | 48 | __all__ = (
|
44 | 49 | "Interaction",
|
@@ -519,6 +524,44 @@ async def delete_original_message(self, **kwargs):
|
519 | 524 | """
|
520 | 525 | return await self.delete_original_response(**kwargs)
|
521 | 526 |
|
| 527 | + async def respond(self, *args, **kwargs) -> Interaction | WebhookMessage: |
| 528 | + """|coro| |
| 529 | +
|
| 530 | + Sends either a response or a message using the followup webhook determined by whether the interaction |
| 531 | + has been responded to or not. |
| 532 | +
|
| 533 | + Returns |
| 534 | + ------- |
| 535 | + Union[:class:`discord.Interaction`, :class:`discord.WebhookMessage`]: |
| 536 | + The response, its type depending on whether it's an interaction response or a followup. |
| 537 | + """ |
| 538 | + try: |
| 539 | + if not self.response.is_done(): |
| 540 | + return await self.response.send_message(*args, **kwargs) |
| 541 | + else: |
| 542 | + return await self.followup.send(*args, **kwargs) |
| 543 | + except InteractionResponded: |
| 544 | + return await self.followup.send(*args, **kwargs) |
| 545 | + |
| 546 | + async def edit(self, *args, **kwargs) -> InteractionMessage | None: |
| 547 | + """|coro| |
| 548 | +
|
| 549 | + Either respond to the interaction with an edit_message or edits the existing response, determined by |
| 550 | + whether the interaction has been responded to or not. |
| 551 | +
|
| 552 | + Returns |
| 553 | + ------- |
| 554 | + Union[:class:`discord.InteractionMessage`, :class:`discord.WebhookMessage`]: |
| 555 | + The response, its type depending on whether it's an interaction response or a followup. |
| 556 | + """ |
| 557 | + try: |
| 558 | + if not self.response.is_done(): |
| 559 | + return await self.response.edit_message(*args, **kwargs) |
| 560 | + else: |
| 561 | + return await self.edit_original_response(*args, **kwargs) |
| 562 | + except InteractionResponded: |
| 563 | + return await self.edit_original_response(*args, **kwargs) |
| 564 | + |
522 | 565 | def to_dict(self) -> dict[str, Any]:
|
523 | 566 | """
|
524 | 567 | Converts this interaction object into a dict.
|
|
0 commit comments