我正在开发一个Discord bot,我正在想办法让它播放YouTube上的整个播放列表,或者能够单独添加链接。 这方面的资产包括node.js,ESLint,ytdl-core,@discord/opus和ffmpeg(来自此站点)。
有关守则如下:
const ytdl = require('ytdl-core');
const { prefix, token } = require('./config.json');
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (message.content === '!play') {
if (message.channel.type !== 'text') return;
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) {
return message.reply('please join a voice channel first!');
}
voiceChannel.join().then(connection => {
const stream = ytdl('https://www.youtube.com/watch?v=1snEYPg8TXs');
const dispatcher = connection.play(stream);
dispatcher.on('finish', () => voiceChannel.leave());
});
发布的代码没有问题,但正如您所见,它只允许一个YouTube视频。 我对ytdl或任何相关函数一无所知,所以我试着创建一个var playlist=[等],但根本不起作用,因为显然它的设置是为了让它期待一个链接。 播放列表链接仅在完成动作前播放第一首歌曲。
有什么建议吗?
ytdl-core
不支持下载播放列表。 您可能希望尝试使用另一个库(例如ytpl)来获取播放列表中包含的视频,然后将其逐个传递给ytdl-core
。