'use strict'; const { time } = require("discord.js"); const fs = require('fs'); const path = require('path'); module.exports = { name: 'autoban', description: `automatically ban a user if they join the server`, aliases: ['ab', 'banish'], usage: 'ban [reason] [duration]', async execute(client, message, args) { if (!message.member.permissions.has('BanMembers')) { return message.reply({ content: null, embeds: [{ color: 0x8aa2b3, author: { name: message.author.username, icon_url: message.author.displayAvatarURL(), }, description: '<:no:1481811955592466492> you do not have permission to use this command!', footer: { text: `twitter @ ${message.guild.name}`, icon_url: client.user.displayAvatarURL(), }, timestamp: new Date(), }] }); } const user = message.mentions.users.first() || await client.users.fetch(args[0]).catch(() => null); if (!user) { return message.reply({ content: null, embeds: [{ color: 0x8aa2b3, author: { name: message.author.username, icon_url: message.author.displayAvatarURL(), }, description: '<:no:1481811955592466492> please specify a user to autoban!', footer: { text: `twitter @ ${message.guild.name}`, icon_url: client.user.displayAvatarURL(), }, timestamp: new Date(), }] }); } const reason = args.slice(1).join(' ') || 'autobanned (twitter)'; const dbPath = path.join(__dirname, '..', '..', '..', 'db.json'); let db = {}; if (fs.existsSync(dbPath)) { db = JSON.parse(fs.readFileSync(dbPath, 'utf8')); } if (!db.autobans) { db.autobans = {}; } db.autobans[message.guild.id] = user.id; try { await fs.writeFileSync(dbPath, JSON.stringify(db, null, 2)); message.reply({ content: null, embeds: [{ color: 0x8aa2b3, author: { name: message.author.username, icon_url: message.author.displayAvatarURL(), }, description: `<:check:1481811973447356496> ${user.username} has been added to the autoban list!`, footer: { text: `twitter @ ${message.guild.name}`, icon_url: client.user.displayAvatarURL(), }, timestamp: new Date(), }] }); } catch (error) { console.error(error); message.reply({ content: null, embeds: [{ color: 0x8aa2b3, author: { name: message.author.username, icon_url: message.author.displayAvatarURL(), }, description: '<:no:1481811955592466492> an error occurred while trying to add the user to the autoban list!', footer: { text: `twitter @ ${message.guild.name}`, icon_url: client.user.displayAvatarURL(), }, timestamp: new Date(), }] }); } }, };