Stop multiple end events

This commit is contained in:
Amish Shah
2016-08-31 20:44:30 +01:00
parent e42f6b1024
commit a638b6369a
2 changed files with 10 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -49,6 +49,11 @@ class MessageCollector extends EventEmitter {
* @type {CollectorOptions}
*/
this.options = options;
/**
* Whether this collector has stopped collecting Messages.
* @type {Boolean}
*/
this.ended = false;
this.listener = (message => this.verify(message));
this.channel.client.on('message', this.listener);
/**
@@ -93,6 +98,10 @@ class MessageCollector extends EventEmitter {
* @param {string} [reason='user'] an optional reason for stopping the collector.
*/
stop(reason = 'user') {
if (this.ended) {
return;
}
this.ended = true;
this.channel.client.removeListener('message', this.listener);
/**
* Emitted when the Collector stops collecting.