I'm trying to make an event that when someone gives a position to another member or places the position on himself with the administrator's permission, the bot will recognize and punish the member
(but it is not acknowledging or activating the event when executed and there is also no error on the console)...
const { Listener } = require("..")
const { RichEmbed, Permissions } = require("discord.js")
let AntiRaidPerm = [
'ADMINISTRATOR',
'KICK_MEMBERS',
'BAN_MEMBERS',
'MANAGE_CHANNELS',
'MANAGE_ROLES',
'MANAGE_EMOJIS',
'MANAGE_GUILD'
]
module.exports = class MemberRoleUpdate extends Listener {
constructor (client) {
super(client)
this.events = {
memberRoleUpdate: this.memberroleupdate
}
}
async memberroleupdate (role) {
if (!this.client.db || !this.client.db.mongoose.connection) return
if (!role.guild || !role.guild.id) return
let doc = await this.client.db.guilds.get(role.guild.id)
const fetchedLogs = await role.guild.fetchAuditLogs({
limit: 1,
type: 'MEMBER_ROLE_UPDATE',
});
const RoleLog = fetchedLogs.entries.first();
const { executor, target } = RoleLog;
if( executor.id === this.client.user.id ) return;
if(executor.id === role.guild.owner) return;
const adminPerm = new Permissions(target.permissions)
const adminremove = role.guild.roles.get(target.id)
if(adminPerm.has('ADMINISTRATOR') === true) {
const docban = await this.client.db.usersban.get(executor.id)
docban.ban.name = executor.tag
docban.ban.id = executor.id
docban.ban.counta = docban.ban.counta +1
await docban.save()
let count1 = `${docban.ban.counta}`
let limit = `${doc.antiraid.alimit}`
let msg = "Anti-Raid ativado! O usuário {member}"
const newMsg = msg.replace("{member}", executor.tag);
let warnEmbed = new RichEmbed()
.setColor("#f7002c")
.setDescription(newMsg + " foi banido!");
if(count1 >= limit) {
role.guild.member(executor).ban(`Proteção de Cargos ativada - \'${executor.username}\' foi banido!`).then(async msg => {
role.guild.channels.get(doc.antiraid.antilog).send(warnEmbed).catch(()=>{})
console.log('Estou banindo')
const perm = new Permissions(adminremove.permissions);
adminremove.setPermissions(perm.remove('ADMINISTRATOR', ))
role.guild.roles.forEach(async(role) => {
let botrole = role.guild.roles.find("name", "The Anti Raiding")
if(role.position === botrole.position) return;
if(role.position > botrole.position) return;
if (role.hasPermissions(AntiRaidPerm)) {
role.setPermissions(perm.remove(AntiRaidPerm))
}})
}).catch(console.error)
}
}
}
}