【发布时间】:2018-04-13 05:40:13
【问题描述】:
我正在尝试使用 ytdl 和 discord.js 下载并播放从 youtube 获取的音频文件:
ytdl(url)
.pipe(fs.createWriteStream('./music/downloads/music.mp3'));
var voiceChannel = message.member.voiceChannel;
voiceChannel.join().then(connection => {
console.log("joined channel");
const dispatcher = connection.playFile('./music/downloads/music.mp3');
dispatcher.on("end", end => {
console.log("left channel");
voiceChannel.leave();
});
}).catch(err => console.log(err));
isReady = true
我成功地在 ./music/downloads/ 中播放了没有 ytdl 部分的 mp3 文件 (ytdl(url).pipe(fs.createWriteStream('./music/downloads/music.mp3'));)。但是当那部分在代码中时,机器人就会加入和离开。
这是带有 ytdl 部分的输出:
Bot has started, with 107 users, in 43 channels of 3 guilds.
joined channel
left channel
这是没有 ytdl 部分的输出:
Bot has started, with 107 users, in 43 channels of 3 guilds.
joined channel
[plays mp3 file]
left channel
为什么会这样,我该如何解决?
【问题讨论】:
标签: javascript node.js discord.js