aboutsummaryrefslogtreecommitdiff
path: root/bot/src/events/MessageBulkDelete.js
blob: a31638f8c24f12e356a1cb20a3d1dabe20d1c795 (plain) (blame)
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
import { EmbedBuilder, Events, AttachmentBuilder } from 'discord.js';
import { guildSettings } from '../db/models/guild-settings.js';

export default {
    name: Events.MessageBulkDelete,
    async execute(msg, channel) {
        try {
            const guildSetting = await guildSettings.findOne({ where: { guildID: channel.guild.id } });
            if (!guildSetting || !guildSetting.messageLogChannelID) return;

            const logEmbed = new EmbedBuilder()
                .setAuthor({ name: 'AleeBot Logging', iconURL: channel.client.user.avatarURL() })
                .setDescription(`A bulk of ${msg.size} messages were deleted in ${channel}`)
                .setColor('#ff021b')
                .setTimestamp();

            let messages = [];

            msg.forEach(message => {
                messages.push(`[${message.createdAt.toUTCString()}]`);
                messages.push(`${message.author.username} (${message.author.id})`);
                messages.push(`Message (${message.id}): ${message.content}`);
                messages.push('-----------------------------------');
            });

            const messageContent = messages.join('\n');
            const attachment = new AttachmentBuilder(Buffer.from(messageContent, 'utf-8'), { name: 'messages.txt' });

            let deleteMessage = channel.client.channels.cache.get(guildSetting.messageLogChannelID);
            if (!deleteMessage) return;

            await deleteMessage.send({ embeds: [logEmbed], files: [attachment] });
        } catch (e) {
            console.error(e);
        }
    }
};