【问题标题】:Check if a music (streamed from youtube) is playing on bot or not检查是否在机器人上播放音乐(从 youtube 流式传输)
【发布时间】:2020-02-11 17:01:35
【问题描述】:

我刚刚创建了一个工作队列命令,但现在我一直在编辑播放命令

我试图让它如果正在播放音乐,播放命令只会将查询推送到队列并等待音乐完成播放然后转移队列以播放下一个。

我被困在如何检查机器人是否仍在从互联网上播放音乐。

//push function, stream and streamOptions is above from here
if (/*check whether a music is playing = false*/) {
   function dispatcher() {
       connection.playStream(stream, streamOptions)
       dispatcher.on('end', function () {
       lst.shiftlist(); //shift the queue
       if (lst.urllist[0]/*check if queue[0] contains*/) {
          dispatcher();
       }
       else {
          message.channel.send('Queue empty!');
          return;
       }
       })
   }
}
else if (/*check whether a music is playing = true*/) {
     message.channel.send('Added to queue!')
     console.log(url)
}

是否可以检查机器人是否仍在播放流?或者有什么其他方法可以解决这个问题?

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    在我的脑海中,最简单的方法是在音乐开始播放时切换某种状态,并在调度程序结束事件触发时将其关闭。比如:

    var playing = false
    if (/*check whether a music is playing = false*/) {
       function dispatcher() {
           connection.playStream(stream, streamOptions)
           playing = true
           dispatcher.on('end', function () {
           lst.shiftlist(); //shift the queue
           if (lst.urllist[0]/*check if queue[0] contains*/) {
              dispatcher();
           }
           else {
              playing = false
              message.channel.send('Queue empty!');
              return;
           }
           })
       }
    }
    else if (/*check whether a music is playing = true*/) {
         message.channel.send('Added to queue!')
         console.log(url)
    }
    

    【讨论】:

    • 我怎么能这么狭隘,哈哈。谢谢。非常感谢
    猜你喜欢
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 2021-10-25
    相关资源
    最近更新 更多