module.exports = {
name: Events.GuildRoleDelete,
async execute(role) {
try {
// Fetch the audit logs to identify the user who deleted the role
const auditLogs = await role.guild.fetchAuditLogs({
type: AuditLogEvent.RoleDelete,
limit: 1
});
const roleDeleteLog = auditLogs.entries.first();
const { executor, target } = roleDeleteLog;
// Fetch audit logs for member kicks to identify if the deletion was caused by a bot being kicked
const kickLogs = await role.guild.fetchAuditLogs({
type: AuditLogEvent.MemberKick,
limit: 1
});
const kickLog = kickLogs.entries.first();
const kickExecutor = kickLog ? kickLog.executor : null;
const kickTarget = kickLog ? kickLog.target : null;
// Check if the role deletion was caused by kicking a bot
if (kickTarget && kickTarget.bot && kickLog.createdTimestamp >= roleDeleteLog.createdTimestamp) {
return; // Early return if the deletion was caused by kicking a bot
}