From 35329402f63a4afce3feb7c318f4be7faba5ddaf Mon Sep 17 00:00:00 2001 From: "Vladyslav G." Date: Wed, 2 Sep 2026 04:17:32 +0200 Subject: [PATCH] fix(channel): start a thread in a forum without throwing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit startThreadInForumChannel() has never worked. It built its return type as an anonymous class extending Channel — but inside Rest\Channel the bare name is that class itself, since Parts\Channel is imported under an alias. So it extended the REST resource, whose constructor takes three arguments, and every call died on "Too few arguments" before reaching the network. The type it wanted is now a real part. Discord answers this one call with the opening message attached, which is what reactions and edits on the post address, so it is worth a name rather than a cast — and a caller can now be typed against it, which an anonymous class never allowed. No test referenced the method, which is how it stayed broken. --- src/Parts/ForumThread.php | 20 ++++++++++++++++++++ src/Rest/Channel.php | 10 ++++------ tests/Rest/ChannelTest.php | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/Parts/ForumThread.php diff --git a/src/Parts/ForumThread.php b/src/Parts/ForumThread.php new file mode 100644 index 0000000..aeda9bc --- /dev/null +++ b/src/Parts/ForumThread.php @@ -0,0 +1,20 @@ + includes $message property + * @return PromiseInterface<\Tempcord\Discord\Parts\ForumThread> the post, with + * the opening message Discord answers with attached */ public function startThreadInForumChannel( string $channelId, MultipartBody|array $params, ?string $reason = null ): PromiseInterface { - $forumChannelWithMessage = new class () extends Channel { - public Message $message; - }; - return $this->mapPromise( $this->http->post( Endpoint::bind(Endpoint::CHANNEL_THREADS, $channelId), $params, $this->getAuditLogReasonHeader($reason), ), - $forumChannelWithMessage::class, + ForumThread::class, ); } diff --git a/tests/Rest/ChannelTest.php b/tests/Rest/ChannelTest.php index f0bce73..457151b 100644 --- a/tests/Rest/ChannelTest.php +++ b/tests/Rest/ChannelTest.php @@ -5,6 +5,7 @@ namespace Tests\Tempcord\Discord\Rest; use Tempcord\Discord\Parts\ArchivedThreads; +use Tempcord\Discord\Parts\ForumThread; use Tempcord\Discord\Parts\Channel as PartsChannel; use Tempcord\Discord\Parts\Invite; use Tempcord\Discord\Parts\Message; @@ -204,6 +205,20 @@ public static function httpBindingsProvider(): array 'returnType' => PartsChannel::class, ] ], + 'Start thread in forum channel' => [ + 'method' => 'startThreadInForumChannel', + 'args' => ['::channel id::', ['name' => '::post::', 'message' => ['content' => '::text::']]], + 'mockOptions' => [ + 'method' => 'post', + 'return' => (object) [ + 'id' => '::thread id::', + 'message' => (object) ['id' => '::message id::'], + ], + ], + 'validationOptions' => [ + 'returnType' => ForumThread::class, + ] + ], 'Delete channel' => [ 'method' => 'delete', 'args' => ['::channel id::'],