diff --git a/packages/discord.js/src/structures/interfaces/Collector.js b/packages/discord.js/src/structures/interfaces/Collector.js index bcd7528a6..65f411744 100644 --- a/packages/discord.js/src/structures/interfaces/Collector.js +++ b/packages/discord.js/src/structures/interfaces/Collector.js @@ -95,6 +95,20 @@ class Collector extends EventEmitter { if (options.time) this._timeout = setTimeout(() => this.stop('time'), options.time).unref(); if (options.idle) this._idletimeout = setTimeout(() => this.stop('idle'), options.idle).unref(); + + /** + * The timestamp at which this collector last collected an item + * @type {?number} + */ + this.lastCollectedTimestamp = null; + } + + /** + * The Date at which this collector last collected an item + * @type {?Date} + */ + get lastCollectedAt() { + return this.lastCollectedTimestamp && new Date(this.lastCollectedTimestamp); } /** @@ -118,6 +132,7 @@ class Collector extends EventEmitter { */ this.emit('collect', ...args); + this.lastCollectedTimestamp = Date.now(); if (this._idletimeout) { clearTimeout(this._idletimeout); this._idletimeout = setTimeout(() => this.stop('idle'), this.options.idle).unref(); diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index f2a6142fb..7059ba0f8 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1060,6 +1060,8 @@ export abstract class Collector extends EventEmi public readonly client: Client; public collected: Collection; + public lastCollectedTimestamp: number | null; + public get lastCollectedAt(): Date | null; public ended: boolean; public get endReason(): string | null; public filter: CollectorFilter<[V, ...F]>;