add disconnect event, document warn and debug events (#702)

* add documentation for events, and add a disconnect event, because i know people use that

* generate docs, and fix a hastily copied docstring

* fix permissions freak out
This commit is contained in:
Gus Caplan
2016-09-13 23:12:10 -05:00
committed by Schuyler Cebulskie
parent 25531170ec
commit 7cb2e8eef7
6 changed files with 26 additions and 11 deletions

View File

@@ -157,6 +157,11 @@ class WebSocketManager {
* @param {Object} event The received websocket data
*/
eventClose(event) {
/**
* Emitted whenever the client websocket is disconnected
* @event Client#disconnect
*/
if (!this.reconnecting) this.client.emit(Constants.Events.DISCONNECT);
if (event.code === 4004) throw new Error(Constants.Errors.BAD_LOGIN);
if (!this.reconnecting && event.code !== 1000) this.tryReconnect();
}
@@ -224,7 +229,11 @@ class WebSocketManager {
if (this.client.options.fetch_all_members) {
const promises = this.client.guilds.array().map(g => g.fetchMembers());
Promise.all(promises).then(() => this._emitReady()).catch(e => {
this.client.emit('warn', `Error on pre-ready guild member fetching - ${e}`);
/**
* Emitted when there is a warning
* @event Client#warn
*/
this.client.emit(Constants.Event.WARN, `Error on pre-ready guild member fetching - ${e}`);
this._emitReady();
});
return;