discord-php / DiscordPHP

An API to interact with the popular messaging app Discord
MIT License
992 stars 236 forks source link

Promise Interaction without any value #1200

Closed DT-666 closed 7 months ago

DT-666 commented 7 months ago

Environment [2024-02-21T08:37:56.323915+00:00] DiscordPHP.DEBUG: Initializing DiscordPHP v7.3.5 (DiscordPHP-Http: v9.1.9 & Gateway: v9) on PHP 8.0.30

Describe the bug On a slash command, when i reply or aknowledge, with a premise ->then or ->done, the parameter of the function is always null, not as the sendMessage one which as got the new message object

To Reproduce Steps to reproduce the behavior: $bot->getDiscord()->listenCommand('dt', function (Interaction $interaction) { global $bot; $discord = $bot->getDiscord(); $msg = 'Bonjour DT !'.PHP_EOL; $is_admin = false; if($interaction->user->id == '127425489399840768') { $is_admin = true; $interaction->acknowledge()->then( function (Interaction $interaction) { echo 'ackT', PHP_EOL; var_dump($interaction); $interaction->sendFollowUpMessage(MessageBuilder::new()->setContent('go'), true); }, function ($error) { echo 'ackT', PHP_EOL; var_dump($error); } ) ->done( function (Interaction $interaction) { echo 'ackD', PHP_EOL; var_dump($interaction); $interaction->sendFollowUpMessage(MessageBuilder::new()->setContent('go'), true); }, function ($error) { echo 'ackD', PHP_EOL; var_dump($error); } ); }; });

Expected behavior having the parameter of $interaction->sendFollowUpMessage with the value of listenCommand('dt', function (Interaction $interaction) {

It's the same with the functino replyMessage

Additional context Logs : [2024-02-21T08:38:00.492972+00:00] DiscordPHP.DEBUG: http not checking {"waiting":0,"empty":true} [] ackD object(TypeError)#4776 (7) { ["message":protected]=> string(218) "{closure}(): Argument #1 ($interaction) must be of type Discord\Parts\Interactions\Interaction, null given, called in C:\PHP\www\include\discord\DiscordPHP-7.3.4\vendor\react\promise\src\FulfilledPromise.php on line 28" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(47) "C:\PHP\www\bots\discord\swgoh\commands\test.php" ["line":protected]=> int(25) ["trace":"Error":private]=> array(40) { [0]=>

SQKo commented 7 months ago

This works as expected, responding to interaction returns no content as specified in the endpoint https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response Unlike normal send message which does return a message data https://discord.com/developers/docs/resources/channel#create-message Same for listenCommand() there is $interaction argument because the interaction data is received from the event https://discord.com/developers/docs/topics/gateway-events#interaction-create

If you wish to get your last interaction object, pass it inside function () use ($interaction)