mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Add client.destroy();
This commit is contained in:
@@ -105,6 +105,8 @@ class Client extends EventEmitter {
|
||||
* @type {?Number}
|
||||
*/
|
||||
this.readyTime = null;
|
||||
this._intervals = [];
|
||||
this._timeouts = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +137,32 @@ class Client extends EventEmitter {
|
||||
return this.rest.methods.loginToken(email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the client and logs out. Resolves with null if successful.
|
||||
* @returns {Promise<null, Error>}
|
||||
*/
|
||||
destroy() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.manager.destroy().then(() => {
|
||||
this._intervals.map(i => clearInterval(i));
|
||||
this._timeouts.map(t => clearTimeout(t));
|
||||
this.token = null;
|
||||
this.email = null;
|
||||
this.password = null;
|
||||
resolve();
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(...params) {
|
||||
this._intervals.push(setInterval(...params));
|
||||
}
|
||||
|
||||
setTimeout(...params) {
|
||||
this._timeouts.push(setTimeout(...params));
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches a user, or obtains it from the cache if it's already cached.
|
||||
* If the user isn't already cached, it will only be obtainable by OAuth bot accounts.
|
||||
|
||||
Reference in New Issue
Block a user