mirror of
https://github.com/danbulant/discord.js
synced 2026-07-06 19:50:55 +00:00
add guild sharding support (#393)
* add guild sharding support * squash if statements
This commit is contained in:
parent
a073010197
commit
00e3708e78
4 changed files with 30 additions and 6 deletions
|
|
@ -77,6 +77,13 @@ var Client = (function (_EventEmitter) {
|
||||||
this.options.largeThreshold = options.largeThreshold || 250;
|
this.options.largeThreshold = options.largeThreshold || 250;
|
||||||
this.options.maxCachedMessages = options.maxCachedMessages || 1000;
|
this.options.maxCachedMessages = options.maxCachedMessages || 1000;
|
||||||
this.options.guildCreateTimeout = options.guildCreateTimeout || 1000;
|
this.options.guildCreateTimeout = options.guildCreateTimeout || 1000;
|
||||||
|
this.options.shardId = options.shardId || 0;
|
||||||
|
this.options.shardCount = options.shardCount || 0;
|
||||||
|
|
||||||
|
if (typeof options.shardCount === "number" && typeof options.shardId === "number" && options.shardCount > 0) {
|
||||||
|
this.options.shard = [options.shardId, options.shardCount];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal Client that the Client wraps around.
|
* Internal Client that the Client wraps around.
|
||||||
* @readonly
|
* @readonly
|
||||||
|
|
|
||||||
|
|
@ -1649,8 +1649,7 @@ var InternalClient = (function () {
|
||||||
this.websocket = new _ws2["default"](url);
|
this.websocket = new _ws2["default"](url);
|
||||||
|
|
||||||
this.websocket.onopen = function () {
|
this.websocket.onopen = function () {
|
||||||
|
var data = {
|
||||||
self.sendWS({
|
|
||||||
op: 2,
|
op: 2,
|
||||||
d: {
|
d: {
|
||||||
token: self.token,
|
token: self.token,
|
||||||
|
|
@ -1665,7 +1664,13 @@ var InternalClient = (function () {
|
||||||
"$referring_domain": "discord.js"
|
"$referring_domain": "discord.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (self.client.options.shard) {
|
||||||
|
data.d.shard = self.client.options.shard;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sendWS(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onclose = function (code) {
|
this.websocket.onclose = function (code) {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,13 @@ export default class Client extends EventEmitter {
|
||||||
this.options.largeThreshold = options.largeThreshold || 250;
|
this.options.largeThreshold = options.largeThreshold || 250;
|
||||||
this.options.maxCachedMessages = options.maxCachedMessages || 1000;
|
this.options.maxCachedMessages = options.maxCachedMessages || 1000;
|
||||||
this.options.guildCreateTimeout = options.guildCreateTimeout || 1000;
|
this.options.guildCreateTimeout = options.guildCreateTimeout || 1000;
|
||||||
|
this.options.shardId = options.shardId || 0;
|
||||||
|
this.options.shardCount = options.shardCount || 0;
|
||||||
|
|
||||||
|
if (typeof options.shardCount === "number" && typeof options.shardId === "number" && options.shardCount > 0) {
|
||||||
|
this.options.shard = [options.shardId, options.shardCount];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal Client that the Client wraps around.
|
* Internal Client that the Client wraps around.
|
||||||
* @readonly
|
* @readonly
|
||||||
|
|
|
||||||
|
|
@ -1430,8 +1430,7 @@ export default class InternalClient {
|
||||||
this.websocket = new WebSocket(url);
|
this.websocket = new WebSocket(url);
|
||||||
|
|
||||||
this.websocket.onopen = () => {
|
this.websocket.onopen = () => {
|
||||||
|
var data = {
|
||||||
self.sendWS({
|
|
||||||
op: 2,
|
op: 2,
|
||||||
d: {
|
d: {
|
||||||
token: self.token,
|
token: self.token,
|
||||||
|
|
@ -1446,7 +1445,13 @@ export default class InternalClient {
|
||||||
"$referring_domain": "discord.js"
|
"$referring_domain": "discord.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (self.client.options.shard) {
|
||||||
|
data.d.shard = self.client.options.shard;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sendWS(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.websocket.onclose = (code) => {
|
this.websocket.onclose = (code) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue