在语音通道中获取自我静音者的ID

时间:2020-09-12 13:02:54

标签: node.js discord discord.js

每当他们使用Discord.jS在语音通道中使自己静音时,我想获得一个人的User对象。

示例:

if (somebody has muted themselves)
{
   const member = user.id;
}

1 个答案:

答案 0 :(得分:1)

您可以收听Client#voiceStateUpdate事件。每当语音状态更新时,它将触发。 (这包括成员使自己静音的时间。)

VoiceState具有一个名为selfMute(布尔值)的属性,该属性指示成员是否使自己静音。您可以使用serverMute查看该成员是否被服务器静音。


client.on("voiceStateUpdate", (oldVoiceState, newVoiceState) => {
    if (oldVoiceState.selfMute !== newVoiceState.selfMute) {
        if (newVoiceState.selfMute) {
            console.log(`${newVoiceState.member.user.tag} muted themselves!`);
        };
    };
});