在计算持续时间之前,机器人会断开连接

时间:2019-08-05 21:52:47

标签: javascript node.js discord.js

我对一个机器人进行了编码,然后我使用ytdl-core来获取视频长度,而ive却超时了,其中视频长度为* 1000才能获取毫秒,但是获取该长度并计算它却花费了太长时间,因此该机器人会在知道应该停留多长时间之前断开连接

我尝试将getInfo调高(这就是代码现在使用的内容) 但是我不想让整个功能超时 整个文件: https://gist.github.com/ScarVite/dcedca2b9ae913b40f7e8f009f1e871c

ytdl.getInfo(queue[0]).then(info => {
                        length = (info.length_seconds * 1000)
                        message.channel.setTopic(':musical_note: **Derzeit Läuft**: "' + info.title + '" Länge: ' + sectomin(info.length_seconds))
                        console.log(length)
                    });

//and at the bottom of the code

if (queue[0] !== undefined) {
                        setTimeout(function(){
                            if (message.guild.voiceConnection !== null) {
                                console.log('Here')
                                message.guild.voiceConnection.disconnect();
                            }
                    }, length)
                    setTimeout(this.streamyt, length, message)
                }
                else {
                    setTimeout(function () {
                        message.channel.send('Das Lied ist Vorbei')
                        if (message.guild.voiceConnection !== null) {
                            message.guild.voiceConnection.disconnect();
                            message.channel.setTopic("Starte einen song mit -play <youtube link>")
                        }
                    }, length)
                    }

它应该获取信息和歌曲的长度,并计算秒数以毫秒为单位,然后连接并播放该歌曲,然后在持续播放时间后应断开连接,但实际上它会更快地达到超时值需要它才能计算长度,甚至开始播放歌曲,您只需quickyl听到连接,然后断开连接的声音,控制台甚至输出(http://light-theme-hurts.my-ey.es/5DJXTtu.png),零秒是它需要之前的超时值而47000是歌曲的实际长度,是在需要超时值之后计算的

0 个答案:

没有答案
相关问题