检索负责的用户以在discord.js中删除频道

时间:2019-05-15 09:26:26

标签: javascript node.js discord discord.js

我正在建立一个警报系统,如果有人删除某个频道,它会发送一条消息,其中包含已删除的频道的名称和Deleter,因此我尝试通过对 this 进行编码:

client.on('channelDelete', channel => {
  var channelDeleteAuthor = channelDelete.action.author
  const lChannel = message.channels.find(ch => ch.name === 'bot-logs')
  if (!channel) return; channel.send(`Channel Deleted by ${channelDeleteAuthor}`)
  .then(message => console.log(`Channel Deleted by ${channelDeleteAuthor}`))
  .catch(console.error)

})

它没有用,我该怎么做?

1 个答案:

答案 0 :(得分:2)

要查找删除的作者,您需要分析公会审核日志。

client.on('channelDelete', channel => {
  // get the channel ID
  const channelDeleteId = channel.id;

  // finds all channel deletions in the log
  channel.guild.fetchAuditLogs({'type': 'CHANNEL_DELETE'}) 
  // find the log entry for this specific channel
  .then( logs => logs.entries.find(entry => entry.target.id == channelDeleteId) ) 
  .then (entry => {
    // get the author of the deletion
    author = entry.executor;

    // do whatever you want
    console.log(`channel ${channel.name} deleted by ${author.tag}`);
  })
  .catch(error => console.error(error));

})