From 102e5a8a3dbfcb7723877e44dcb172b91c1443be Mon Sep 17 00:00:00 2001 From: Nico Date: Tue, 24 Oct 2023 01:03:06 -0400 Subject: [PATCH] fix: stop collecting on time expiration (#245) * fix: stop collecting on time expiration * Create twelve-avocados-draw.md * chore: prettier --- .changeset/twelve-avocados-draw.md | 5 +++++ .../guilded.js/lib/structures/collectors/Collector.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/twelve-avocados-draw.md diff --git a/.changeset/twelve-avocados-draw.md b/.changeset/twelve-avocados-draw.md new file mode 100644 index 00000000..15086812 --- /dev/null +++ b/.changeset/twelve-avocados-draw.md @@ -0,0 +1,5 @@ +--- +"guilded.js": patch +--- + +fix: stop collecting on time expiration diff --git a/packages/guilded.js/lib/structures/collectors/Collector.ts b/packages/guilded.js/lib/structures/collectors/Collector.ts index 8a447f79..b4fe8a9e 100644 --- a/packages/guilded.js/lib/structures/collectors/Collector.ts +++ b/packages/guilded.js/lib/structures/collectors/Collector.ts @@ -40,7 +40,13 @@ export abstract class Collector { start(): Promise> { return new Promise((resolve) => { this.resolve = resolve; - this.maxTimeout = setTimeout(() => resolve({ reason: CollectorEndReasons.TIME, entries: this.entries }), this.options.timeLimit); + + this.maxTimeout = setTimeout(() => { + this.resolve!({ reason: CollectorEndReasons.TIME, entries: this.entries }); + this._cleanup(); + this.isActive = false; + }, this.options.timeLimit); + this.hookEvents(); this.isActive = true; });