![](/img/trans.png)
[英]How to get the count field in messageReaction collection 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
)隊列處於活動狀態。 有人可以建議如何過濾隊列對象以返回大小/長度/計數嗎?
您可以使用find()
查找queue
並獲取其length
var playlistList = client.playlists.find(playlist => playlist.queue).length
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.