mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-20 13:33:30 +01:00
feat(Collector): Addition of resetTimer() (#3825)
* feat(Collector): Addition of resetTimer() * typings
This commit is contained in:
@@ -188,6 +188,23 @@ class Collector extends EventEmitter {
|
|||||||
this.emit('end', this.collected, reason);
|
this.emit('end', this.collected, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the collectors timeout and idle timer.
|
||||||
|
* @param {Object} [options] Options
|
||||||
|
* @param {number} [options.time] How long to run the collector for in milliseconds
|
||||||
|
* @param {number} [options.idle] How long to stop the collector after inactivity in milliseconds
|
||||||
|
*/
|
||||||
|
resetTimer({ time, idle } = {}) {
|
||||||
|
if (this._timeout) {
|
||||||
|
this.client.clearTimeout(this._timeout);
|
||||||
|
this._timeout = this.client.setTimeout(() => this.stop('time'), time || this.options.time);
|
||||||
|
}
|
||||||
|
if (this._idletimeout) {
|
||||||
|
this.client.clearTimeout(this._idletimeout);
|
||||||
|
this._idletimeout = this.client.setTimeout(() => this.stop('idle'), idle || this.options.idle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the collector should end, and if so, ends it.
|
* Checks whether the collector should end, and if so, ends it.
|
||||||
*/
|
*/
|
||||||
|
|||||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -337,6 +337,7 @@ declare module 'discord.js' {
|
|||||||
public handleCollect(...args: any[]): void;
|
public handleCollect(...args: any[]): void;
|
||||||
public handleDispose(...args: any[]): void;
|
public handleDispose(...args: any[]): void;
|
||||||
public stop(reason?: string): void;
|
public stop(reason?: string): void;
|
||||||
|
public resetTimer(options?: { time?: number, idle?: number }): void;
|
||||||
public [Symbol.asyncIterator](): AsyncIterableIterator<V>;
|
public [Symbol.asyncIterator](): AsyncIterableIterator<V>;
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user