mirror of
https://github.com/danbulant/discord.js
synced 2026-05-25 13:02:38 +00:00
add option for guilds per shard, and fix type (#1053)
This commit is contained in:
parent
2156ce1e15
commit
2b25641270
1 changed files with 4 additions and 3 deletions
|
|
@ -3,17 +3,18 @@ const botGateway = require('./Constants').Endpoints.botGateway;
|
|||
|
||||
/**
|
||||
* Gets the recommended shard count from Discord
|
||||
* @param {number} token Discord auth token
|
||||
* @param {string} token Discord auth token
|
||||
* @param {number} [guildsPerShard=1000] Number of guilds per shard
|
||||
* @returns {Promise<number>} the recommended number of shards
|
||||
*/
|
||||
module.exports = function fetchRecommendedShards(token) {
|
||||
module.exports = function fetchRecommendedShards(token, guildsPerShard = 1000) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!token) throw new Error('A token must be provided.');
|
||||
superagent.get(botGateway)
|
||||
.set('Authorization', `Bot ${token.replace(/^Bot\s*/i, '')}`)
|
||||
.end((err, res) => {
|
||||
if (err) reject(err);
|
||||
resolve(res.body.shards);
|
||||
resolve(res.body.shards * (1000 / guildsPerShard));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue