youtube - Discord.js-音乐机器人。它播放任何视频,但不播放受版权保护的音乐

标签 youtube discord discord.js audio-player

此命令可以正常播放任何视频,但是如果是视频音乐或带有音乐的东西,则不会播放任何视频
我该怎么办?

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

filter - Used to decide what format to download. Can be audioandvideo to filter formats that contain both video and audio, video to filter for formats that contain video, or videoonly for formats that contain video and no additional audio track. Can also be audio or audioonly. You can give a filtering function that gets called with each format available. This function is given the format object as its first argument, and should return true if the format is preferable.



如果不是那样,YouTube自身可能会在自己的事业上有所作为。

关于youtube - Discord.js-音乐机器人。它播放任何视频,但不播放受版权保护的音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58959953/

相关文章:

python - 如何让我的 Discord 机器人看起来像是正在打字?

discord.js - 获取对旧消息的旧 react

objective-c - iOS 应用程序使用 GData 将视频上传到 youtube 并使用 JSON 框架导致重复错误

android - 使用 jsoup 从站点 url 中提取 youtube 视频 url

android - Android HttpPost从Youtube获取 “Invalid request URI”

python - 我如何在 Python 中为 discord 机器人创建重新加载命令?

python - 有没有办法创建一个命令来列出在不和谐服务器中具有特定角色的每个人?

audio - 音乐 discord.js 机器人 : The "url" argument must be of type string

javascript - 如何让 Discord 机器人收听我的 DM,而不是简单的 channel 消息?

php - 如何以分页方式从 YouTube 获取用户视频