discord-php / DiscordPHP

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

Channel duplication on edit #1164

Closed xWildFire closed 1 year ago

xWildFire commented 1 year ago

Environment

Describe the bug A clear and concise description of what the bug is.

After last changes with channels in dev-master something broke and editing channel sometimes duplicates the channel which is editing

To Reproduce Steps to reproduce the behavior:

i'm using it in a timer to update it every x minutes

        $this->browser->get("XXXX")->then(function (ResponseInterface $response) use ($guild, $channelId) {
            $content = $response->getBody()->getContents();
            $guild->channels->fetch($channelId)->then(function (Channel $channel) use ($content) {
                if ($content === '1') {
                    $channelName = "🔴┇offline";
                } else {
                    $channelName = "🟢┇online";
                }
                if ($channel->name !== $channelName) {
                    $channel->name = $channelName;
                    $channel->guild->channels->save($channel);
                }
            });
        });

At this moment got no logs because i've cleared them, but i will send when it happens again.

key2peace commented 1 year ago

besides needing to add $channelId to the use in the first line (which has no contribution to this bug. Could you dump $channel->created, as a temp fix you could also put $channel->created = true; before the save. However, what you first need to take a look at are the debug logs, I want to know if you see a PATCH or a POST when save is being executed (should be PATCH)

xWildFire commented 1 year ago

logs:

[24.07.2023, 13:48:41] [DEBUG] sending heartbeat {"seq":259238}
[24.07.2023, 13:48:41] [DEBUG] received heartbeat ack {"response_time":123.39115142822266}
[24.07.2023, 13:48:56] [DEBUG] resetting payload count {"count":2}
[24.07.2023, 13:49:00] [DEBUG] BUCKET postchannels/850659415782981632/messages queued REQ POST channels/850659415782981632/messages 
[24.07.2023, 13:49:00] [DEBUG] REQ POST channels/850659415782981632/messages successful 
[24.07.2023, 13:49:00] [DEBUG] http not checking {"waiting":0,"empty":true}
[24.07.2023, 13:49:22] [DEBUG] sending heartbeat {"seq":259551}
[24.07.2023, 13:49:22] [DEBUG] received heartbeat ack {"response_time":114.48097229003906}
[24.07.2023, 13:49:56] [DEBUG] resetting payload count {"count":1}
[24.07.2023, 13:50:03] [DEBUG] sending heartbeat {"seq":259881}
[24.07.2023, 13:50:03] [DEBUG] received heartbeat ack {"response_time":115.05389213562012}
[24.07.2023, 13:50:16] [DEBUG] BUCKET patchchannels/1081566704930402364/messages/:message_id queued REQ PATCH channels/1081566704930402364/messages/1081567495363760201 
[24.07.2023, 13:50:16] [DEBUG] BUCKET postguilds/484723871887392772/channels queued REQ POST guilds/484723871887392772/channels 
[24.07.2023, 13:50:16] [DEBUG] REQ PATCH channels/1081566704930402364/messages/1081567495363760201 successful 
[24.07.2023, 13:50:16] [DEBUG] http not checking {"waiting":1,"empty":true}
[24.07.2023, 13:50:16] [DEBUG] REQ POST guilds/484723871887392772/channels successful 
[24.07.2023, 13:50:16] [DEBUG] http not checking {"waiting":0,"empty":true}
[24.07.2023, 13:50:20] [DEBUG] BUCKET postinteractions/:interaction_id/:interaction_token/callback queued REQ POST interactions/1133003231686041600/token/callback 
[24.07.2023, 13:50:20] [DEBUG] BUCKET patchguilds/484723871887392772/members/:user_id queued REQ PATCH guilds/484723871887392772/members/440170209957904405 
[24.07.2023, 13:50:21] [DEBUG] REQ POST interactions/1133003231686041600/token/callback successful 
[24.07.2023, 13:50:21] [DEBUG] http not checking {"waiting":1,"empty":true}
[24.07.2023, 13:50:21] [DEBUG] BUCKET getchannels/1130477162571509861 queued REQ GET channels/1130477162571509861 
[24.07.2023, 13:50:21] [DEBUG] BUCKET postchannels/850659415782981632/messages queued REQ POST channels/850659415782981632/messages 
[24.07.2023, 13:50:21] [DEBUG] REQ PATCH guilds/484723871887392772/members/440170209957904405 successful 
[24.07.2023, 13:50:21] [DEBUG] http not checking {"waiting":2,"empty":true}
[24.07.2023, 13:50:21] [DEBUG] BUCKET postwebhooks/:application_id/:interaction_token queued REQ POST webhooks/818942332514205698/token 
[24.07.2023, 13:50:21] [DEBUG] REQ GET channels/1130477162571509861 successful 
[24.07.2023, 13:50:21] [DEBUG] http not checking {"waiting":2,"empty":true}
[24.07.2023, 13:50:21] [DEBUG] BUCKET deletechannels/1130477162571509861 queued REQ DELETE channels/1130477162571509861 
[24.07.2023, 13:50:21] [DEBUG] REQ POST channels/850659415782981632/messages successful 
[24.07.2023, 13:50:21] [DEBUG] http not checking {"waiting":2,"empty":true}
[24.07.2023, 13:50:21] [DEBUG] REQ POST webhooks/818942332514205698/token successful 
[24.07.2023, 13:50:21] [DEBUG] http not checking {"waiting":1,"empty":true}
[24.07.2023, 13:50:21] [DEBUG] REQ DELETE channels/1130477162571509861 successful 
[24.07.2023, 13:50:21] [DEBUG] http not checking {"waiting":0,"empty":true}
[24.07.2023, 13:50:44] [DEBUG] sending heartbeat {"seq":260315}
[24.07.2023, 13:50:45] [DEBUG] received heartbeat ack {"response_time":117.17605590820312}
[24.07.2023, 13:50:56] [DEBUG] resetting payload count {"count":2}
[24.07.2023, 13:51:14] [DEBUG] BUCKET postinteractions/:interaction_id/:interaction_token/callback queued REQ POST interactions/1133003457054376027/token/callback 
[24.07.2023, 13:51:14] [DEBUG] BUCKET patchwebhooks/:application_id/:interaction_token/messages/@original queued REQ PATCH webhooks/818942332514205698/token/messages/@original 
[24.07.2023, 13:51:14] [DEBUG] REQ POST interactions/1133003457054376027/token/callback successful 
[24.07.2023, 13:51:14] [DEBUG] http not checking {"waiting":1,"empty":true}
[24.07.2023, 13:51:15] [DEBUG] REQ PATCH webhooks/818942332514205698/token/messages/@original successful 
[24.07.2023, 13:51:15] [DEBUG] http not checking {"waiting":0,"empty":true}
[24.07.2023, 13:51:26] [DEBUG] sending heartbeat {"seq":260652}
[24.07.2023, 13:51:26] [DEBUG] received heartbeat ack {"response_time":114.36700820922852}
[24.07.2023, 13:51:31] [DEBUG] BUCKET postchannels/1133003527128616990/messages queued REQ POST channels/1133003527128616990/messages 
[24.07.2023, 13:51:31] [DEBUG] BUCKET postchannels/1133003527128616990/messages queued REQ POST channels/1133003527128616990/messages 
[24.07.2023, 13:51:31] [DEBUG] REQ POST channels/1133003527128616990/messages successful 
[24.07.2023, 13:51:31] [DEBUG] http not checking {"waiting":0,"empty":true}
[24.07.2023, 13:51:32] [DEBUG] REQ POST channels/1133003527128616990/messages successful 
[24.07.2023, 13:51:32] [DEBUG] http not checking {"waiting":0,"empty":true}

channel witch should be edited channel_id = 1081566704930402364, guild_id = 484723871887392772 from discord logs i see that duplicate was created 24.07.2023 13:50 there is a POST like you thought

SQKo commented 1 year ago

I actually can't reproduce this, however in #1165 I reverted some part where the created status might be wrong referenced especially in HTTP request

xWildFire commented 1 year ago

Updated my bot and deleted ->created = true; to test that and it happened again. I have one more function that fetches message on this channel and edits it, maybe thats causing this problem when it works together?

SQKo commented 1 year ago

without code we know nothing please also post your composer.lock and discord options

also try using fetch with fresh parameter set to true

xWildFire commented 1 year ago

example code, something like that

            $this->browser->get("XXXX")->then(function (ResponseInterface $response) use ($guild, $channelId, $messageId) {
                $content = $response->getBody()->getContents();
                $guild->channels->fetch($channelId)->then(function (Channel $channel) use ($content, $messageId) {
                    if ($content === '1') {
                        $channelName = "🔴┇offline";
                    } else {
                        $channelName = "🟢┇online";
                    }
                    $channel->messages->fetch($messageId)->then(function (Message $message) use ($channelName) {
                        $content = $message->content;
                        if ($content !== $channelName) {
                            $message->edit(MessageBuilder::new()->setContent($channelName));
                        }
                    });
                    if ($channel->name !== $channelName) {
                        $channel->name = $channelName;
                        //$channel->created = true;  // with this it's working fine
                        $channel->guild->channels->save($channel);
                    }
                });
            });

composer.txt

SQKo commented 1 year ago

please show larger portion of the code scope, we dont even know when it is called

also you didnt provide your $discord options

SQKo commented 1 year ago

I cannot reproduce this without clear information, I tested your code and nothing is wrong. If you are currently using external cache storage such as redis, please clear it first after updating.

Reply here if you still need to discuss more