aboutsummaryrefslogtreecommitdiff
path: root/src/commands/dev/servers.ts
blob: 6bba93c664f8fe2a1421f383e4171dbedc5a1a7e (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
import {
	BotCommand,
	ButtonPaginator,
	chunk,
	clientSendAndPermCheck,
	colors,
	format,
	type CommandMessage,
	type SlashMessage
} from '#lib';
import { stripIndent } from '#tags';
import { type APIEmbed, type Guild } from 'discord.js';

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

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

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