mirror of
https://github.com/danbulant/discord.js
synced 2026-05-25 21:12:06 +00:00
19 lines
639 B
JavaScript
19 lines
639 B
JavaScript
const superagent = require('superagent');
|
|
const botGateway = require('./Constants').Endpoints.botGateway;
|
|
|
|
/**
|
|
* Gets the recommended shard count from Discord
|
|
* @param {number} token Discord auth token
|
|
* @returns {Promise<number>} the recommended number of shards
|
|
*/
|
|
module.exports = function getRecommendedShards(token) {
|
|
return new Promise((resolve, reject) => {
|
|
if (!token) throw new Error('A token must be provided.');
|
|
superagent.get(botGateway)
|
|
.set('Authorization', `Bot ${token.replace(/^Bot /, '')}`)
|
|
.end((err, res) => {
|
|
if (err) reject(err);
|
|
resolve(res.body.shards);
|
|
});
|
|
});
|
|
};
|