discord.js user.speaking无效

时间:2017-11-10 18:09:55

标签: discord discord.js

//function fires after special command every 100 milliseconds
function searchSpeaking(roleSpeak){

    //checks every channel; giving you member-channel and its chanId-id
    bot.channels.forEach((channel, chanId) => {
        //filters out text channels
        if (channel.type == 'voice'){
            //checks every member in voice channel; giving you guildMember-user and his/her id
            channel.members.forEach((guildMember, memberId) => {
                //debug
                console.log(guildMember.nickname, guildMember.speaking)
                console.log("-----------------------------------")
                //activates when user speaks DOESN'T WORK
                if (guildMember.speaking){
                    //adds 'score' it means how mayn milli seconds user talks
                    scoreboard[memberId] += 100
                    console.log("user is speaking!")
                    //if user talks for over 30s = 30 000 milliseconds and has option to talk
                    if ((scoreboard[memberId] > 30 * 1000) && guildMember.roles.has(roleSpeak.id)){
                        //reset his score and remove his option to speak
                        scoreboard[memberId] = 0
                        guildMember.removeRole(roleSpeak)
                    }
                }
                //if user isnt talking because his option/role to talk was removed
                else if (!(guildMember.roles.has(roleSpeak.id))){
                    //we messure how much time he/she has been muted/without talking option
                    scoreboard[memberId] += 100
                    //if he/she was muted for a minute he/she will get his option/role to talk back 
                    if (scoreboard[id] > 60 * 1000){
                        //reset score and give back role
                        scoreboard[memberId] = 0
                        guildMember.addRole(roleSpeak)
                    }
                }
            })
        }

    })
}

所以在注释(//)下的行中声明这不起作用是一个if语句,即使用户在通道中说话也不会通过。它也是console.loging的错误(显而易见)。所以我无法弄清楚为什么我理解文档,每次成员说话时都应该转为真。我将再次这样说(正如它在第一个代码注释中所说),此函数每100ms = 0.1s触发一次,并根据代码注释中进一步解释的分数获得应该更改的角色。

感谢您使用.speaking的任何帮助!

1 个答案:

答案 0 :(得分:1)

使用当前的API,无法可以知道用户是否在语音频道中进行通话而未加入语音频道
您需要加入语音频道,获取正在通话的用户列表,然后切换到另一个频道(如果该频道中有任何成员)。
使用此方法,您可能会很快得到限速 只有在没有加入频道的情况下,才能获得语音频道中的成员列表,并过滤那些麦克风静音的成员。你仍然不知道他们是否真的在说话。

如果你想加入频道,那么"听"说到,你可以使用事件guildMemberSpeaking。只要用户在你的语音通道中开始/停止讲话,这就会激活。