const { PermissionFlagsBits, EmbedBuilder, Collection } = require("discord.js"); const messageCount = new Map(); const timeoutUsers = new Set(); const maxMessageCount = 5; const recentMessages = new Collection(); module.exports = async (client, message) => { if (!message.guild || message.author.bot || message.member.permissions.has(PermissionFlagsBits.ManageMessages)) { return; } const { member, author, guild, channel, content } = message; const channelId = '1180155996639862834'; const timeoutDuration = 2 * 60 * 60 * 1000; if (recentMessages.has(content.toLowerCase())) { const spamMessages = [...recentMessages.values()].filter(msg => msg.content.toLowerCase() === content.toLowerCase()); if (spamMessages.length > 1) { try { const chunkSize = 100; for (let i = 0; i < spamMessages.length; i += chunkSize) { const chunk = spamMessages.slice(i, i + chunkSize); await channel.bulkDelete(chunk); } } catch (error) { console.error(error); } } } recentMessages.set(content.toLowerCase(), message); setTimeout(() => { recentMessages.delete(content); }, timeoutDuration); if (messageCount.get(author.id) >= maxMessageCount && !timeoutUsers.has(author.id)) { member.timeout(timeoutDuration, 'Spam'); timeoutUsers.add(author.id); setTimeout(() => { timeoutUsers.delete(author.id); }, timeoutDuration); const logChannel = guild.channels.cache.get(channelId); if (logChannel) { const logEmbed = new EmbedBuilder() .setColor('Red') .setTitle('Timeout durch Anti-Spam') .setDescription(`:alarm_clock: <@${author.id}> wurde für Spam getimeoutet.`) .addFields( { name: 'Dauer', value: '2 Stunden', inline: true }, { name: 'Grund', value: 'Spam', inline: true }, ); logChannel.send({ embeds: [logEmbed] }); messageCount.set(author.id, 0); } else { console.error('Log-Kanal wurde nicht gefunden!'); } } else { const userMessageCount = messageCount.get(author.id) || 0; messageCount.set(author.id, userMessageCount + 1); } };