我正在做一个NodeJS音乐机器人,我突然遇到了一个问题。机器人适当地加入频道,亮起灯(表示它在说话),但是没有声音。在试图找出问题的根源之后,我认为这是来自ytdl-core模块的ytdl-core函数的一个问题。
const stream = await ytdl(song.url, {
filter: 'audioonly',
type: 'opus',
highWaterMark: waterMark
});看看溪流的结果,我发现:
PassThrough {
_readableState: ReadableState {
objectMode: false,
highWaterMark: 524288,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
...这意味着我没有得到任何缓冲区/流数据。这的确是在演奏,但因为没有什么--只有沉默才能被听到。
我试着使用pipe(),它工作得很好,但是我不能通过我的音乐机器人来播放它。
发布于 2022-02-23 14:57:50
ytdl函数类似于同步函数。
"ytdl-core": "^4.10.1"
const stream = await ytdl(song.url);暂停代码执行,直到ytdl完成下载流。
console.log("YTDL Start");
const stream = await ytdl(song.url, {
filter: 'audioonly',
type: 'opus',
highWaterMark: waterMark
});
console.log("Is it done?");
stream.on('close', () => {
console.log('Read stream closed');
});
stream.on('finish', () => {
console.log('Read stream Finished');
});https://stackoverflow.com/questions/69975640
复制相似问题