【问题标题】:Voice Channel Audit-log语音通道审核日志
【发布时间】:2021-10-10 07:00:37
【问题描述】:
      let newUserChannel = newMember.voiceChannel
      let oldUserChannel = oldMember.voiceChannel


      if(oldUserChannel === undefined && newUserChannel !== undefined) {
      send_log(
        c,
        newMember.guild,
        "RED",
        "Voice Channel",
        `${newMember.user} has joined ${newUserChannel}`

      )
     } else if(newUserChannel === undefined){
      send_log(
        c,
        newMember.guild,
        "RED",
        "Voice Channel",
        `${newMember.user} has left'd ${oldUserChannel}`
      )
    // User leaves a voice channel

  }
})

没有提出任何错误。但是在用户离开或加入任何 VC 后,它会这样说。 ${newMember.user} 调出undefined${oldUserChannel} 也调出未定义。

【问题讨论】:

  • 等待 cmets...

标签: javascript discord.js


【解决方案1】:

这是一个可以帮助你的简短代码

client.on('voiceStateUpdate', async (oldM, newM) => {
    if(!oldM.channel && newM.channel) {
        send_log(
        c,
        newM.guild,
        "RED",
        "Voice Channel",
        `${newM.member.user} joined ${newM.channel.name}`
         )
    } else if(oldM.channel && newM.channel && oldM.channel?.id !== newM.channel?.id) {
        send_log(
        c,
        newM.member.guild,
        "RED",
        "Voice Channel",
        `${newM.member.user} switched from ${oldM.channel.name} to ${newM.channel.name}`
         )
    } else if(oldM.channel && !newM.channel) {
        send_log(
        c,
        newM.guild,
        "RED",
        "Voice Channel",
        `${newM.member.user} left ${oldM.channel.name}`
         )
    }
})

我不知道c 是什么,所以你可能需要在某个地方定义它。

【讨论】:

  • 任何人...请帮我缩进,我在移动设备上,我还在学习(如果它很好,我怀疑,告诉我)
  • 看起来不错,here 是我在电脑上看到的。我个人也会缩进 send_log() 函数调用中的行。但取决于我猜的偏好。如果您希望我建议对此进行编辑,请告诉我。我也可能会为缩进使用更少的空间,所以它不会占用太多的水平空间。
  • 再次感谢@MrMythical 的回复,但是... UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'channel' of undefined
  • 太好了!顺便说一句,@MrMythical 你可能应该用来自 cmets 的信息更新你的答案。
  • 我更新了。感谢您让我知道这件事。
猜你喜欢
  • 1970-01-01
  • 2018-10-27
  • 1970-01-01
  • 2021-07-11
  • 2019-02-21
  • 1970-01-01
  • 2019-10-02
  • 2018-07-09
  • 2016-03-23
相关资源
最近更新 更多