From 70e91b9175bf3da825ecaaa106bad81647c8deff Mon Sep 17 00:00:00 2001 From: loicbersier Date: Tue, 2 Jun 2020 23:25:41 +0200 Subject: [PATCH] Log role deletion Signed-off-by: loicbersier --- event/listeners/log/roleDelete.js | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 event/listeners/log/roleDelete.js diff --git a/event/listeners/log/roleDelete.js b/event/listeners/log/roleDelete.js new file mode 100644 index 00000000..e65218ad --- /dev/null +++ b/event/listeners/log/roleDelete.js @@ -0,0 +1,38 @@ +const { Listener } = require('discord-akairo'); +const LogStats = require('../../../models/').LogStats; + +class roleDeleteListener extends Listener { + constructor() { + super('roleDelete', { + emitter: 'client', + event: 'roleDelete' + }); + } + + async exec(role) { + const guild = role.guild; + const logStats = await LogStats.findOne({where: {guild: guild.id}}); + if (logStats) { + const fetchedLogs = await guild.fetchAuditLogs({ + limit: 1, + type: 'ROLE_DELETE', + }); + + const creationLog = fetchedLogs.entries.first(); + + const channel = this.client.channels.resolve(await logStats.get('channel')); + let Embed = this.client.util.embed() + .setColor('NAVY') + .setTitle('Role deleted') + .setDescription(`${role.name} got deleted!`) + .setTimestamp(); + + if (!creationLog) return channel.send(Embed); + + Embed.setDescription(`${role.name} got deleted by ${creationLog.executor}`); + + channel.send(Embed); + } + } +} +module.exports = roleDeleteListener;