aboutsummaryrefslogtreecommitdiff
path: root/src/commands/dev/servers.ts
blob: 308d1dbece57bc939d87840cea4eb5a4e2f6de98 (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
import { BushCommand, ButtonPaginator, type BushMessage, type BushSlashMessage } from '#lib';
import { type Guild, type MessageEmbedOptions } from 'discord.js';

export default class ServersCommand extends BushCommand {
	public constructor() {
		super('servers', {
			aliases: ['servers', 'guilds'],
			category: 'dev',
			description: 'Displays all the severs the bot is in',
			usage: ['servers'],
			examples: ['servers'],
			clientPermissions: (m) => util.clientSendAndPermCheck(m),
			userPermissions: [],
			ownerOnly: true
		});
	}

	public override async exec(message: BushMessage | BushSlashMessage) {
		const guilds = [...client.guilds.cache.sort((a, b) => (a.memberCount < b.memberCount ? 1 : -1)).values()];
		const chunkedGuilds: Guild[][] = util.chunk(guilds, 10);
		const embeds: MessageEmbedOptions[] = chunkedGuilds.map((chunk) => {
			return {
				title: `Server List [\`${guilds.length.toLocaleString()}\`]`,
				color: util.colors.default,
				fields: chunk.map((guild) => ({
					name: util.format.input(guild.name),
					value: [
						`**ID:** ${guild.id}`,
						`**Owner:** ${client.users.cache.has(guild.ownerId) ? client.users.cache.get(guild.ownerId)!.tag : guild.ownerId}`,
						`**Members:** ${guild.memberCount.toLocaleString()}`
					].join('\n')
				}))
			} as MessageEmbedOptions;
		});

		return await ButtonPaginator.send(message, embeds);
	}
}