import { Command } from 'discord-akairo'; import { Message } from 'discord.js'; export default class BanMod extends Command { public constructor() { super('ban', { aliases: ['ban', 'banish'], category: 'moderation', description: { content: 'Ban a specified user from the server.', usage: '[user] [reason(s)]', examples: [ '@fun#1337', '@fun#1337 too cool' ] }, ratelimit: 3, channel: 'guild', clientPermissions: ['BAN_MEMBERS'], userPermissions: ['BAN_MEMBERS'], args: [ { id: 'user', type: 'string', prompt: { start: 'Which user would you like to ban?', retry: 'That doesn\'t seem to be a user, please try again!' } }, { id: 'reason', type: 'string', prompt: { start: 'For what reason would you like to ban this user?', optional: true }, match: 'rest' } ] }); } public async exec(msg: Message, { user, reason }): Promise { if (msg.mentions.members.first()) user = msg.mentions.members.first().id; if (user === this.client.user.id) return msg.channel.send('You can\'t ban me!'); if (!reason) reason = 'No reason has been specified.'; if (user === msg.author.id) return msg.channel.send('You can\'t ban yourself!'); if (msg.mentions.members.first()) { user = msg.mentions.members.first(); await user.send(`You have been banned from **${msg.guild.name}** for the following reason(s): "**${reason}**".`) .catch(() => console.log('[ERROR] Could not send message to this user.')); return user.ban({ reason: `Banned by: ${msg.author.username} for the following reason(s): ${reason}.`}) .then(() => msg.reply(`${user.user.username} was successfully banned with the following reason(s): "**${reason}**".`)) .catch(err => console.error(err)); } else { msg.guild.members.ban(user, { reason: `Banned by: ${msg.author.username} for the following reason(s): ${reason}.`}) .then(() => msg.reply(`User ID ${user} was successfully banned with the following reason(s): "**${reason}**".`)) .catch(err => console.error(err)); } } }