lexy
lexy
DIAdiscord.js - Imagine an app
Created by lexy on 6/25/2024 in #djs-questions
Help with GuildRoleDelete Event
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
}
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
}
Hey guys I need help with my code so what Im trying to do is 😆 when ever user kicks or bans a bot from the server GuildRoleDelete event gets triggered and Ive been trying to stop that . Ive spent last 2-3 hours trying to solve this but couldnt come up with solution.
7 replies