const { Client, GatewayIntentBits } = require('discord.js'); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, ], }); const fs = require('fs'); const token = ''; const prefix = '/'; const welcomeChannelID = ''; const farewellChannelID = ''; const modLogChannelID = ''; client.on('ready', () => { console.log(`Il bot è online come ${client.user.tag}`); }); client.on('messageCreate', async (message) => { if (message.author.bot) return; if (message.content.startsWith(prefix)) { const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); if (command === 'clear') { if (!args[0]) return message.reply('Specifica la quantità di messaggi da cancellare.'); const amount = parseInt(args[0]) + 1; if (isNaN(amount)) return message.reply('La quantità specificata non è valida.'); message.channel.bulkDelete(amount, true).catch((err) => { console.error(err); message.channel.send('Si è verificato un errore durante la cancellazione dei messaggi.'); }); console.log('Comando clear eseguito!'); } if (command === 'moderate') { const wordsToFilter = ['word1', 'word2']; for (const word of wordsToFilter) { if (message.content.toLowerCase().includes(word)) { message.delete(); message.reply('Il tuo messaggio contiene una parola vietata.'); message.member.ban({ reason: 'Parola vietata nel messaggio' }) .then((member) => { message.channel.send(`${member.user.tag} è stato bannato per utilizzo di parole vietate.`); logBan(member, message.author, 'Parola vietata nel messaggio'); }) .catch((error) => console.error(error)); break; } } } } }); client.on('guildMemberAdd', (member) => { const welcomeChannel = client.channels.cache.get(welcomeChannelID); if (welcomeChannel) { const welcomeMessage = `Benvenuto/a su ${member.guild.name}, ${member}!`; const imagePath = ''; welcomeChannel.send(welcomeMessage, { files: [imagePath] }); } }); client.on('guildMemberRemove', (member) => { const farewellChannel = client.channels.cache.get(farewellChannelID); if (farewellChannel) { const farewellMessage = `Addio, ${member.user.tag}! Speriamo che tu possa tornare presto.`; const imagePath = ''; farewellChannel.send(farewellMessage, { files: [imagePath] }); } }); function logBan(member, executor, reason) { const modLogChannel = client.channels.cache.get(modLogChannelID); if (modLogChannel) { const logMessage = `${executor.tag} ha bannato ${member.user.tag} per il motivo: ${reason}`; modLogChannel.send(logMessage); } } client.login(token);