首页 > 解决方案 > 如何检测到用户从一个语音通道更改为另一个语音通道?

问题描述

例如,我想检测某人何时从“Talk I”变为“Talk II”。但它应该可以在同时不断开服务器的情况下工作,然后加入“Talk II”!有没有办法做到这一点??

标签: discord.js

解决方案


每次用户更新他们的语音状态时,客户端都会发出一个voiceStateUpdate事件。
要检测用户是否更改了他们的语音通道,您可以执行以下操作:

client.on('voiceStateUpdate', (oldMember, newMember) => {
  let oldChannel = oldMember.voiceChannel, // the previous channel, if there was one
    newChannel = newMember.voiceChannel; // the current channel, if there is one

  if (oldChannel != newChannel) { // if the channel has changed
    // do your stuff...
  }
});

推荐阅读