aboutsummaryrefslogtreecommitdiff
path: root/src/listeners/guild/guildCreate.ts
blob: c4d33a5cbcfa295bff1cf17b0794f512c5d36de4 (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
import { BotListener, colors, Emitter, emojis, format, Guild, type BotClientEvents } from '#lib';
import { Events } from 'discord.js';

export default class GuildCreateListener extends BotListener {
	public constructor() {
		super('guildCreate', {
			emitter: Emitter.Client,
			event: Events.GuildCreate // when the bot joins a guild
		});
	}

	public async exec(...[guild]: BotClientEvents[Events.GuildCreate]) {
		void this.client.console.info(
			'guildCreate',
			`Joined <<${guild.name}>> with <<${guild.memberCount?.toLocaleString()}>> members.`
		);
		const g = await Guild.findByPk(guild.id);
		if (!g) void Guild.create({ id: guild.id });

		const channel = await this.client.utils.getConfigChannel('servers');
		if (!channel) return;
		return await channel.send({
			embeds: [
				{
					color: colors.Green,
					description: `${emojis.join} Joined ${format.input(
						guild.name
					)} with **${guild.memberCount?.toLocaleString()}** members. I am now in **${this.client.guilds.cache.size}** guilds.`,
					timestamp: new Date().toISOString(),
					footer: { text: `${guild.id}`, icon_url: guild.iconURL() ?? undefined }
				}
			]
		});
	}
}