mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
Add Sharding Support!
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,4 +1,5 @@
|
|||||||
const DocumentedItem = require('./DocumentedItem');
|
const DocumentedItem = require('./DocumentedItem');
|
||||||
|
const DocumentedParam = require('./DocumentedParam');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
{ id: 'Client()',
|
{ id: 'Client()',
|
||||||
@@ -18,13 +19,26 @@ const DocumentedItem = require('./DocumentedItem');
|
|||||||
class DocumentedConstructor extends DocumentedItem {
|
class DocumentedConstructor extends DocumentedItem {
|
||||||
|
|
||||||
registerMetaInfo(data) {
|
registerMetaInfo(data) {
|
||||||
|
super.registerMetaInfo(data);
|
||||||
this.directData = data;
|
this.directData = data;
|
||||||
|
const newParams = [];
|
||||||
|
for (const param of data.params) {
|
||||||
|
newParams.push(new DocumentedParam(this, param));
|
||||||
|
}
|
||||||
|
this.directData.params = newParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize() {
|
serialize() {
|
||||||
super.serialize();
|
super.serialize();
|
||||||
const { id, name, description, memberof, access } = this.directData;
|
const { id, name, description, memberof, access, params } = this.directData;
|
||||||
return { id, name, description, memberof, access };
|
return {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
memberof,
|
||||||
|
access,
|
||||||
|
params: params.map(p => p.serialize())
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,6 +112,9 @@ class WebSocketManager {
|
|||||||
this.reconnecting = false;
|
this.reconnecting = false;
|
||||||
const payload = this.client.options.ws;
|
const payload = this.client.options.ws;
|
||||||
payload.token = this.client.token;
|
payload.token = this.client.token;
|
||||||
|
if (this.client.options.shard_count > 0) {
|
||||||
|
payload.shard = [this.client.options.shard_id, this.client.options.shard_count];
|
||||||
|
}
|
||||||
|
|
||||||
this.send({
|
this.send({
|
||||||
op: Constants.OPCodes.IDENTIFY,
|
op: Constants.OPCodes.IDENTIFY,
|
||||||
|
|||||||
@@ -1,3 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* Options that can be passed to a client:
|
||||||
|
* ```js
|
||||||
|
* {
|
||||||
|
* ws: {
|
||||||
|
* large_threshold: 250,
|
||||||
|
* compress: true,
|
||||||
|
* properties: {
|
||||||
|
* $os: process ? process.platform : 'discord.js',
|
||||||
|
* $browser: 'discord.js',
|
||||||
|
* $device: 'discord.js',
|
||||||
|
* $referrer: '',
|
||||||
|
* $referring_domain: '',
|
||||||
|
* },
|
||||||
|
* },
|
||||||
|
* protocol_version: 6,
|
||||||
|
* max_message_cache: 200,
|
||||||
|
* rest_ws_bridge_timeout: 5000,
|
||||||
|
* api_request_method: 'sequential',
|
||||||
|
* shard_id: 0,
|
||||||
|
* shard_count: 0,
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
* @typedef {Object} ClientOptions
|
||||||
|
*/
|
||||||
exports.DefaultOptions = {
|
exports.DefaultOptions = {
|
||||||
ws: {
|
ws: {
|
||||||
large_threshold: 250,
|
large_threshold: 250,
|
||||||
@@ -14,6 +39,8 @@ exports.DefaultOptions = {
|
|||||||
max_message_cache: 200,
|
max_message_cache: 200,
|
||||||
rest_ws_bridge_timeout: 5000,
|
rest_ws_bridge_timeout: 5000,
|
||||||
api_request_method: 'sequential',
|
api_request_method: 'sequential',
|
||||||
|
shard_id: 0,
|
||||||
|
shard_count: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.Status = {
|
exports.Status = {
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
const Discord = require('../');
|
const Discord = require('../');
|
||||||
const request = require('superagent');
|
const request = require('superagent');
|
||||||
|
|
||||||
const client = new Discord.Client();
|
const client = new Discord.Client({
|
||||||
|
shard_id: 0,
|
||||||
|
shard_count: 2,
|
||||||
|
});
|
||||||
|
|
||||||
client.login(require('./auth.json').token).then(token => console.log('logged in with token ' + token)).catch(console.log);
|
client.login(require('./auth.json').token).then(token => console.log('logged in with token ' + token)).catch(console.log);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user