mirror of
https://github.com/danbulant/discord.js
synced 2026-06-09 09:42:22 +00:00
Events are only received when the Client is ready for it
Without this, any messages received during startup could cause crashes
This commit is contained in:
parent
6589814789
commit
d3ae0ccb8c
1 changed files with 7 additions and 2 deletions
9
index.js
9
index.js
|
|
@ -17,7 +17,7 @@ exports.Client = function( options ) {
|
||||||
this.websocket = null;
|
this.websocket = null;
|
||||||
this.events = {};
|
this.events = {};
|
||||||
this.user = null;
|
this.user = null;
|
||||||
|
this.ready = false;
|
||||||
this.serverList = new List( "id" );
|
this.serverList = new List( "id" );
|
||||||
this.PMList = new List( "id" );
|
this.PMList = new List( "id" );
|
||||||
|
|
||||||
|
|
@ -25,6 +25,10 @@ exports.Client = function( options ) {
|
||||||
|
|
||||||
exports.Client.prototype.triggerEvent = function( event, args ) {
|
exports.Client.prototype.triggerEvent = function( event, args ) {
|
||||||
|
|
||||||
|
if ( !this.ready ) { //if we're not even loaded yet, don't try doing anything because it always ends badly!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( this.events[ event ] ) {
|
if ( this.events[ event ] ) {
|
||||||
this.events[ event ].apply( this, args );
|
this.events[ event ].apply( this, args );
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -149,6 +153,7 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
||||||
client.cacheServer( sID, function( server ) {
|
client.cacheServer( sID, function( server ) {
|
||||||
cached++;
|
cached++;
|
||||||
if ( cached >= toCache ) {
|
if ( cached >= toCache ) {
|
||||||
|
client.ready = true;
|
||||||
client.triggerEvent( "ready" );
|
client.triggerEvent( "ready" );
|
||||||
}
|
}
|
||||||
}, _server.members );
|
}, _server.members );
|
||||||
|
|
@ -391,7 +396,7 @@ exports.Client.prototype.sendMessage = function( channel, message, cb, _mentions
|
||||||
//Channel is an ID
|
//Channel is an ID
|
||||||
var chanId = channel;
|
var chanId = channel;
|
||||||
channel = {
|
channel = {
|
||||||
id : chanId
|
id: chanId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue