【问题标题】:discord.js user.speaking isn't workingdiscord.js user.speaking 不起作用
【发布时间】:2018-04-24 00:52:45
【问题描述】:
//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 也是错误的(很明显)。所以我不明白为什么当我理解文档时,每次成员说话时它都应该变成真的。我会再说一遍(正如它在第一个代码注释中所说),此函数每 100 毫秒 = 0.1 秒触发一次,并根据代码 cmets 中进一步解释的分数获得一个应该改变的角色。

感谢您在使用 .speaking 时提供的任何帮助!

【问题讨论】:

  • 您还在为此烦恼吗?我不确定你是如何在不和谐的Collection 上使用.forEach() - 这在文档中不可用哈哈

标签: discord discord.js


【解决方案1】:

使用当前 API,无法知道用户是否在语音频道中讲话不加入语音频道
您需要加入一个语音频道,获取正在交谈的用户列表,然后切换到另一个频道(如果该频道中有任何成员)。
使用这种方法,您可能会很快得到rate limited
唯一不加入频道的方法是获取语音频道中的成员列表,并过滤麦克风静音的成员。你仍然不知道他们是否真的在说话。

如果您想加入频道并“收听”演讲,您可以使用活动guildMemberSpeaking。每当用户开始/停止在您所在的语音频道中讲话时,这都会激活。

【讨论】:

    猜你喜欢
    • 2018-01-13
    • 1970-01-01
    • 2022-01-05
    • 2020-12-25
    • 2022-10-14
    • 2019-09-23
    • 2020-09-04
    • 2020-09-13
    • 2021-10-13
    相关资源
    最近更新 更多