aboutsummaryrefslogtreecommitdiff
path: root/src/commands/dev/servers.ts
blob: c86e8896fe5fd5885c6789d855d8ca3fa241d794 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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', 'guilds'],
			category: 'dev',
			description: {
				content: 'Displays all the severs the bot is in',
				usage: 'servers',
				examples: ['servers']
			},
			clientPermissions: ['SEND_MESSAGES'],
			userPermissions: ['SEND_MESSAGES'],
			ownerOnly: true
		});
	}

	public override async exec(message: BushMessage | BushSlashMessage): Promise<unknown> {
		const maxLength = 10;
		const guilds = [...client.guilds.cache.sort((a, b) => (a.memberCount < b.memberCount ? 1 : -1)).values()];
		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 = 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 [\`${client.guilds.cache.size.toLocaleString()}\`]`)
					.setColor(util.colors.default);
			});
			embeds.push(embed);
		});

		return await util.buttonPaginate(message, embeds);
	}
}