0

我不断收到“x 不是函数”错误,无法弄清楚是什么原因造成的。

我已经尝试将播放列表管理器附加到 StreamData,但它仍然不接受它。

除了 PlaylistManager 是一个空对象之外,流数据在 on finish 发出中正确返回,并且当它到达调用 PlaylistManager 的行时,它说它不是一个函数。

// From The Stream Manager File
PlaylistManager = require('../Playlists/PlaylistManager')
const Streams = new Map()
const addFinishListener = function (StreamData) {
    StreamData.stream.on('finish', async () => {
        console.log("Song Ended. Emitting finish. Asking the PlaylistManager to Play the Next Track...")
        StreamData.PlaylistManager.play_next_track(StreamData)
    })
}
// [Create New Stream]
// Plays the next when stream emites finished.
const createNewStream = function (Broadcast, PlaylistName, track) {
    const stream = yt(track.url, request_options)
    broadcast = Broadcast.play(stream)
    let StreamData = {
        stream,
        track,
        broadcast,
        PlaylistName
    }
    StreamData.PlaylistManager = PlaylistManager

    addFinishListener(StreamData)
    Streams.set(PlaylistName, StreamData)
    return stream;
}

错误 :

/// The Output:
Song Ended. Emitting finish. Asking the PlaylistManager to Play the Next Track...
(node:2432) UnhandledPromiseRejectionWarning: TypeError: StreamData.PlaylistManager.play_next_track is not a function
    at PassThrough.<anonymous> (C:\Users\jayca\Documents\Code\MyNextDiscordBot\src\service\broadcast\Streams\StreamManager.js:27:36)
    at PassThrough.emit (events.js:327:22)
    at Object.debug (C:\Users\jayca\Documents\Code\MyNextDiscordBot\src\service\broadcast\Streams\StreamManager.js:52:23)
    at processCommand (C:\Users\jayca\Documents\Code\MyNextDiscordBot\src\service\channel\bot-commands.js:27:27)
    at Object.on (C:\Users\jayca\Documents\Code\MyNextDiscordBot\src\service\channel\bot-commands.js:15:9)
    at C:\Users\jayca\Documents\Code\MyNextDiscordBot\src\service\onMessage.js:11:21
    at Array.forEach (<anonymous>)
    at Client.<anonymous> (C:\Users\jayca\Documents\Code\MyNextDiscordBot\src\service\onMessage.js:9:18)
    at Client.emit (events.js:315:20)
    at MessageCreateAction.handle (C:\Users\jayca\Documents\Code\MyNextDiscordBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
4

0 回答 0