diff --git a/src/Query/Query.php b/src/Query/Query.php index 8ecdf09e..b0c9eddd 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -395,8 +395,14 @@ public function get(): MessageCollection { * @throws ResponseException */ public function chunked(callable $callback, int $chunk_size = 10, int $start_chunk = 1): void { + $start_chunk = max($start_chunk,1); + $chunk_size = max($chunk_size,1); + $skipped_messages_count = $chunk_size * ($start_chunk-1); + $available_messages = $this->search(); - if (($available_messages_count = $available_messages->count()) > 0) { + $available_messages_count = max($available_messages->count() - $skipped_messages_count,0); + + if ($available_messages_count > 0) { $old_limit = $this->limit; $old_page = $this->page;