From 315d101486f7f6d782aecbdd1ec9c75d595d9aa0 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Tue, 2 Jun 2020 23:31:37 +0200 Subject: [PATCH] Log role creation Signed-off-by: loicbersier --- event/listeners/log/roleCreate.js | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 event/listeners/log/roleCreate.js diff --git a/event/listeners/log/roleCreate.js b/event/listeners/log/roleCreate.js new file mode 100644 index 00000000..05ce4055 --- /dev/null +++ b/event/listeners/log/roleCreate.js @@ -0,0 +1,38 @@ +const { Listener } = require('discord-akairo'); +const LogStats = require('../../../models/').LogStats; + +class roleCreateListener extends Listener { + constructor() { + super('roleCreate', { + emitter: 'client', + event: 'roleCreate' + }); + } + + 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_CREATE', + }); + + const creationLog = fetchedLogs.entries.first(); + + const channel = this.client.channels.resolve(await logStats.get('channel')); + let Embed = this.client.util.embed() + .setColor('NAVY') + .setTitle('New role') + .setDescription(`${role.name} got created!`) + .setTimestamp(); + + if (!creationLog) return channel.send(Embed); + + Embed.setDescription(`${role.name} got created by ${creationLog.executor}`); + + channel.send(Embed); + } + } +} +module.exports = roleCreateListener;