【问题标题】:Retrieve responsible user for channel delete in discord.js在 discord.js 中检索负责频道删除的用户
【发布时间】:2019-05-16 18:41:30
【问题描述】:

我正在制作一个警报系统,如果有人删除一个频道,它会发送一条消息,其中包含已删除频道的名称和删除者,所以我尝试通过编码 this 来制作它: p>

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)

})

它不起作用,我该如何实现该操作?

【问题讨论】:

  • 什么变量没有定义?
  • var channelDeleteAuthor = channelDelete.action.author
  • 我想你知道变量是什么
  • 并非如此。它可能是channelDeletemessage,因为它们都没有在您显示的代码中定义。那么,它们是如何/在哪里定义的?或者至少在哪里/如何定义channelDelete
  • 我正在尝试找到如何提及删除器的方法

标签: javascript node.js discord discord.js


【解决方案1】:

要找到删除的作者,需要解析公会审核日志。

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));

})

【讨论】:

    猜你喜欢
    • 2019-04-01
    • 2021-07-31
    • 1970-01-01
    • 2019-09-05
    • 2020-10-15
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 2020-09-19
    相关资源
    最近更新 更多