feat(events/guild): Adding the handling of guildBanAdd event
This commit is contained in:
parent
d121765e88
commit
5c22f2dd25
1 changed files with 64 additions and 0 deletions
64
src/events/guild/guildBanAdd.ts
Normal file
64
src/events/guild/guildBanAdd.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import {
|
||||
AuditLogEvent,
|
||||
Channel,
|
||||
EmbedBuilder,
|
||||
Events,
|
||||
Guild,
|
||||
GuildAuditLogs,
|
||||
GuildBan,
|
||||
User,
|
||||
} from 'discord.js';
|
||||
import { Guild as GuildPrisma } from '@prisma/client';
|
||||
import { prisma } from '@lib/prisma';
|
||||
|
||||
export default {
|
||||
name: Events.GuildBanAdd,
|
||||
async execute(ban: GuildBan) {
|
||||
const guild: Guild = ban.guild;
|
||||
const banned_user: User = ban.user;
|
||||
const fetchedLogs: GuildAuditLogs<AuditLogEvent.MemberBanAdd> = await guild.fetchAuditLogs({
|
||||
limit: 5,
|
||||
type: AuditLogEvent.MemberBanAdd,
|
||||
});
|
||||
const banLog = fetchedLogs.entries.find(
|
||||
(entry) => entry.target?.id === banned_user.id,
|
||||
);
|
||||
const executor: string = banLog.executor.username ?? 'Unknown executor';
|
||||
const reason: string = ban.reason ?? banLog.reason ?? 'No reason provided';
|
||||
const guildData: GuildPrisma = await prisma.guild.findUnique({
|
||||
where: {
|
||||
id: guild.id,
|
||||
},
|
||||
});
|
||||
|
||||
const toSend: EmbedBuilder = new EmbedBuilder()
|
||||
.setTitle('🔨 | Member banned')
|
||||
.setAuthor({
|
||||
name: `${banned_user.username} (${banned_user.id})`,
|
||||
iconURL: banned_user.displayAvatarURL({
|
||||
size: 2048,
|
||||
extension: 'png',
|
||||
}),
|
||||
})
|
||||
.setColor(guildData.color)
|
||||
.setFooter({
|
||||
text: guildData.footer,
|
||||
})
|
||||
.setTimestamp().setDescription(`
|
||||
**Banned by:**
|
||||
${executor}
|
||||
**Reason:**
|
||||
${reason}
|
||||
`);
|
||||
if (guildData.logMod) {
|
||||
const logChannel: Channel | null = await guild.client.channels.fetch(
|
||||
guildData.logMod,
|
||||
);
|
||||
if (logChannel) {
|
||||
logChannel.send({
|
||||
embeds: [toSend],
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue