此命令可以正常播放任何视频,但是如果是视频音乐或带有音乐的东西,则不会播放任何视频我该怎么办?
const ytdl = require('ytdl-core')
module.exports.run = async (client, message, args) => {
if (!message.member.voiceChannel) return message.channel.send('Please connect to a voice channel to play music.')
if (message.guild.me.voiceChannel) return message.channel.send('Bot is already connected.')
if (!args[0]) return message.channel.send('Please put a working Youtube Link.')
let validate = await ytdl.validateURL(args[0])
if (!validate) return message.channel.send('The link is not working.')
let connection = await message.member.voiceChannel.join()
let stream = ytdl(args[0], {filter: 'audioonly'})
let dispatcher = await connection.playStream(stream)
dispatcher.on('end', _end => {message.member.voiceChannel.leave()})
}
module.exports.help = {
name: 'music',
aliases: []
}
尝试删除过滤器:
let stream = ytdl(args[0])
看来可能是过滤了错误的内容。
https://www.npmjs.com/package/ytdl-core 过滤器-用于决定要下载的格式。可以是音频和视频以过滤格式既包含视频又包含音频的视频,用于过滤包含视频的格式的视频或仅视频,用于包含视频且没有其他音轨的格式。也可以是音频或仅音频。您可以提供一种过滤函数,每种格式都可以调用该函数可用。该函数的第一个参数是format对象,应该如果首选格式,则返回true。
如果不是那样,YouTube本身可能会在做自己的事情。