简体   繁体   中英

How can I find who deleted the role on "roleDeltete" in discord.js

I'm on v13 of discord.js and when I run this client.on('roleDelete', a => { console.log(a); }); it only logs deleted: true don't show who deleted. Can somebody help me about how can I find who deleted the role on "roleDelete" event?

在此处输入图像描述

Use audit logs. The bot will need permissions though:

client.on("roleDelete", async role => {
  let member;
  try {
    const log = await role.guild.fetchAuditLogs({ 
      type: "ROLE_DELETE"
    })
    member = role.guild.members.resolve(log.entries.first().executor)
  } catch (err) {
    console.log(err) // simply for debugging
  }
  if (!member) member = null
})

And now when you access member , it will show null if it couldn't find the executor, but will show the GuildMember who deleted the role if they were found.

I would recommend you do it through audit logs.

This might help: https://discordjs.guide/popular-topics/audit-logs.html#some-quick-background

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM