discord-php / DiscordPHP

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

Message startThread not populating thread attribute #1074

Closed ellisonpatterson closed 1 year ago

ellisonpatterson commented 1 year ago

Environment

Describe the bug When creating a thread linked to a message, the thread attribute does not get updated. As @SQKo said, it should update the thread attribute in the THREAD_CREATE event, but it seems to not be working. I tried with THREAD_CREATE enabled and disabled in the DiscordPHP instance, with $message->thread being null in both scenarios.

To Reproduce Steps to reproduce the behavior:

$channelId = '1051858424029249616';

$discord->getChannel($channelId)->sendMessage(
    \Discord\Builders\MessageBuilder::new()->setContent("Test")
)->then(function($message) {
    var_dump($message->thread?->id);

    return \React\Promise\all([
        \React\Promise\resolve($message),
        $message->startThread([
            'name' => 'Test Thread'
        ])
    ]);
})->then(function(array $promises) {
    var_dump($promises[0]->thread?->id);
    var_dump($promises[1]->id);
});

Expected behavior The thread attribute for Message should have the newly-created thread as its value.

SQKo commented 1 year ago

I was mistaken, it's actually MESSAGE_UPDATE that is responsible to update its thread attribute. Discord API doesn't explain this specifically in their docs. So we do not have the code to handle this yet. Also the data received from event seems too partial where it only contains thread id and channel type, where normally the $message->thread (after fetched manually) would have the thread object and its thread member data:

thread? | channel object | the thread that was started from this message, includes thread member object -- | -- | --

https://discord.com/developers/docs/resources/channel#message-object

I wouldn't fix it right inside startThread() function because that would only fix when the bot starts the thread from code, and not when the bot starts the thread from outside code (or other users starts the thread). So it needs to be handled from the events.

EDIT: MESSAGE_UPDATE does not contain thread object when we create the thread