|
16 | 16 | use Discord\Builders\Components\Component;
|
17 | 17 | use Discord\Builders\Components\ComponentObject;
|
18 | 18 | use Discord\Builders\MessageBuilder;
|
| 19 | +use Discord\Builders\ModalBuilder; |
19 | 20 | use Discord\Exceptions\AttachmentSizeException;
|
20 | 21 | use Discord\Helpers\Collection;
|
21 | 22 | use Discord\Helpers\Multipart;
|
|
69 | 70 | class Interaction extends Part
|
70 | 71 | {
|
71 | 72 | /**
|
72 |
| - * {@inheritDoc} |
| 73 | + * @inheritDoc |
73 | 74 | */
|
74 | 75 | protected $fillable = [
|
75 | 76 | 'id',
|
@@ -647,9 +648,9 @@ public function autoCompleteResult(array $choices): PromiseInterface
|
647 | 648 | *
|
648 | 649 | * @link https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction
|
649 | 650 | *
|
650 |
| - * @param string $title The title of the popup modal, max 45 characters |
651 |
| - * @param string $custom_id Developer-defined identifier for the component, max 100 characters |
652 |
| - * @param array|ComponentObject[] $components Between 1 and 5 (inclusive) components that make up the modal contained in Action Row |
| 651 | + * @param string $title The title of the popup modal, max 45 characters. |
| 652 | + * @param string $custom_id Developer-defined identifier for the component, max 100 characters. |
| 653 | + * @param array|ComponentObject[] $components Between 1 and 5 (inclusive) components that make up the modal. |
653 | 654 | * @param callable|null $submit The function to call once modal is submitted.
|
654 | 655 | *
|
655 | 656 | * @throws \LogicException Interaction is Ping or Modal Submit.
|
@@ -684,6 +685,32 @@ public function showModal(string $title, string $custom_id, array $components, ?
|
684 | 685 | });
|
685 | 686 | }
|
686 | 687 |
|
| 688 | + /** |
| 689 | + * Responds to the interaction with a popup modal. |
| 690 | + * |
| 691 | + * @link https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction |
| 692 | + * |
| 693 | + * @param ModalBuilder $modal The modal. |
| 694 | + * @param callable|null $submit The function to call once modal is submitted. |
| 695 | + * |
| 696 | + * @return PromiseInterface |
| 697 | + */ |
| 698 | + public function respondWithModal($modal, ?callable $submit = null): PromiseInterface |
| 699 | + { |
| 700 | + if ($submit) { |
| 701 | + $this->discord->on(Event::INTERACTION_CREATE, $this->createListener($modal->getCustomId(), $submit, 60 * 15)); |
| 702 | + } |
| 703 | + |
| 704 | + return $this->respond($modal->jsonSerialize())->then(function ($response) use ($modal, $submit) { |
| 705 | + if ($submit) { |
| 706 | + $listener = $this->createListener($modal->getCustomId(), $submit, 60 * 15); |
| 707 | + $this->discord->on(Event::INTERACTION_CREATE, $listener); |
| 708 | + } |
| 709 | + |
| 710 | + return $response; |
| 711 | + }); |
| 712 | + } |
| 713 | + |
687 | 714 | /**
|
688 | 715 | * Creates a listener callback for handling modal submit interactions with a specific custom ID.
|
689 | 716 | *
|
|
0 commit comments