繁体   English   中英

Discord.js集合; 如何从集合中的数组中导航和抓取/计数对象

[英]Discord.js collection; how to navigate and grab/count objects from an array in a collection

我有一个 discord.js Collection ,如下所示: 在此处输入图像描述

Collection(1) [Map] {
  '403547647215927306' => {
    dispatcher: StreamDispatcher {
      _writableState: [WritableState],
      writable: true,
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      player: [AudioPlayer],
      streamOptions: [Object],
      streams: [Object],
      _nonce: 2369,
      _nonceBuffer: <Buffer 00 00 09 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>,
      pausedSince: null,
      _writeCallback: [Function (anonymous)],
      broadcast: undefined,
      _pausedTime: 0,
      _silentPausedTime: 0,
      count: 2369,
      startTime: 1588923698004,
      [Symbol(kCapture)]: false
    },
    queue: [ [Object], [Object], [Object] ],
    connection: null,
    position: 0
  }
}

我想分离并计算调度程序的数量和队列中的对象数量。 我已经能够使用 #dispatcher(s)

var playlistCount = client.playlists.filter(q => q.dispatcher).size // returns 1 for code, 2 for image

但是使用类似的方法

var playlistList = client.playlists.filter(q => q.queue).size // returns 1 for code, 2 for image

这应该是队列中的3首歌曲,而不是1 (或图像中的2 )队列处于活动状态。 有人可以建议如何过滤队列对象以返回大小/长度/计数吗?

queue数组(如果相关) 在此处输入图像描述

您可以使用find()查找queue并获取其length

var playlistList = client.playlists.find(playlist => playlist.queue).length

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM