Skip to content

Commit

Permalink
fix(interaction): showModal callback race condition with other intera…
Browse files Browse the repository at this point in the history
…ction create event
  • Loading branch information
SQKo committed Dec 9, 2023
1 parent c50d947 commit d5ec759
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Discord/Parts/Interactions/Interaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public function showModal(string $title, string $custom_id, array $components, ?
],
])->then(function ($response) use ($custom_id, $submit) {
if ($submit) {
$this->discord->once(Event::INTERACTION_CREATE, function (Interaction $interaction) use ($custom_id, $submit) {
$listener = function (Interaction $interaction) use ($custom_id, $submit, &$listener) {
if ($interaction->type == InteractionType::MODAL_SUBMIT && $interaction->data->custom_id == $custom_id) {
$components = Collection::for(RequestComponent::class, 'custom_id');
foreach ($interaction->data->components as $actionrow) {
Expand All @@ -612,8 +612,10 @@ public function showModal(string $title, string $custom_id, array $components, ?
}
}
$submit($interaction, $components);
$this->discord->removeListener(Event::INTERACTION_CREATE, $listener);
}
});
};
$this->discord->on(Event::INTERACTION_CREATE, $listener);
}

return $response;
Expand Down

0 comments on commit d5ec759

Please sign in to comment.