From 0e848557f2a985fa151122467aee26f6491ab37d Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Tue, 22 Nov 2022 12:25:24 +1100 Subject: [PATCH] log manual bans cuz yes --- src/events/guildBanAdd.ts | 23 +++++++++++++++++++++++ src/events/guildBanRemove.ts | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/events/guildBanAdd.ts create mode 100644 src/events/guildBanRemove.ts diff --git a/src/events/guildBanAdd.ts b/src/events/guildBanAdd.ts new file mode 100644 index 0000000..769c87a --- /dev/null +++ b/src/events/guildBanAdd.ts @@ -0,0 +1,23 @@ +import Discord, { AuditLogEvent } from 'discord.js'; +import { TClient } from '../client'; +export default { + name: 'guildBanAdd', + execute: async(client:TClient, member:Discord.GuildMember)=>{ + const fetchBanlog = await member.guild.fetchAuditLogs({ + limit: 1, + type: AuditLogEvent.MemberBanAdd + }) + const banLog = fetchBanlog.entries.first(); + if (!banLog) return console.log(`${member.user.tag} was banned from ${member.guild.name} but no audit log for this user.`) + const {executor, target, reason } = banLog; + if (target.id == member.user.id) { + const embed = new client.embed().setColor(client.config.embedColorRed).setTimestamp().setThumbnail(member.user.displayAvatarURL({size: 2048})).setTitle(`Member Banned: ${target.tag}`).setDescription(`🔹 **User**\n<@${target.id}>\n\`${target.id}\``).addFields( + {name: '🔹 Moderator', value: `<@${executor.id}> (\`${executor.id}\`)`}, + {name: '🔹 Reason', value: `${reason == null ? 'Reason unspecified': reason}`} + ); + (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [embed]}) + } else { + console.log(`${target.tag} was banned from ${member.guild.name} but no audit log could be fetched.`) + } + } +} \ No newline at end of file diff --git a/src/events/guildBanRemove.ts b/src/events/guildBanRemove.ts new file mode 100644 index 0000000..2230c58 --- /dev/null +++ b/src/events/guildBanRemove.ts @@ -0,0 +1,23 @@ +import Discord, { AuditLogEvent } from 'discord.js'; +import { TClient } from '../client'; +export default { + name: 'guildBanRemove', + execute: async(client:TClient, member:Discord.GuildMember)=>{ + const fetchUnbanlog = await member.guild.fetchAuditLogs({ + limit: 1, + type: AuditLogEvent.MemberBanRemove + }) + const unbanLog = fetchUnbanlog.entries.first(); + if (!unbanLog) return console.log(`${member.user.tag} was unbanned from ${member.guild.name} but no audit log for this user.`) + const { executor, target, reason } = unbanLog; + if (target.id == member.user.id) { + const embed = new client.embed().setColor(client.config.embedColorGreen).setTimestamp().setThumbnail(member.user.displayAvatarURL({size: 2048})).setTitle(`Member Unbanned: ${target.tag}`).setDescription(`🔹 **User**\n<@${target.id}>\n\`${target.id}\``).addFields( + {name: '🔹 Moderator', value: `<@${executor.id}> (\`${executor.id}\`)`}, + {name: '🔹 Reason', value: `${reason == null ? 'Reason unspecified.': reason}`} + ); + (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [embed]}) + } else { + console.log(`${target.tag} was unbanned from ${member.guild.name} but no audit log could be fetched.`) + } + } +} \ No newline at end of file