diff options
Diffstat (limited to 'src/commands/dev/servers.ts')
-rw-r--r-- | src/commands/dev/servers.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/commands/dev/servers.ts b/src/commands/dev/servers.ts new file mode 100644 index 0000000..08f74e8 --- /dev/null +++ b/src/commands/dev/servers.ts @@ -0,0 +1,48 @@ +import { Guild, MessageEmbed } from 'discord.js'; +import { BushCommand, BushMessage, BushSlashMessage } from '../../lib'; + +export default class ServersCommand extends BushCommand { + public constructor() { + super('servers', { + aliases: ['servers'], + category: 'dev', + description: { + content: 'Displays all the severs the bot is in', + usage: 'servers', + examples: ['servers'] + }, + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES'], + superUserOnly: true + }); + } + + public async exec(message: BushMessage | BushSlashMessage): Promise<unknown> { + const maxLength = 10; + const guilds = this.client.guilds.cache.sort((a, b) => (a.memberCount < b.memberCount ? 1 : -1)).array(); + const chunkedGuilds: Guild[][] = []; + const embeds: MessageEmbed[] = []; + + for (let i = 0, j = guilds.length; i < j; i += maxLength) { + chunkedGuilds.push(guilds.slice(i, i + maxLength)); + } + + chunkedGuilds.forEach((c: Guild[]) => { + const embed = new MessageEmbed(); + c.forEach((g: Guild) => { + const owner = this.client.users.cache.get(g.ownerId)?.tag; + embed + .addField( + `**${g.name}**`, + `**ID:** ${g.id}\n**Owner:** ${owner ? owner : g.ownerId}\n**Members:** ${g.memberCount.toLocaleString()}`, + false + ) + .setTitle('Server List') + .setColor(this.client.util.colors.default); + }); + embeds.push(embed); + }); + + return await this.client.util.buttonPaginate(message, embeds); + } +} |