0

我一直在开发一个自定义的不和谐机器人,主要是为了好玩,但也为了一些朋友。每当有人使用该命令时,我都想在语音聊天中流式传输直播 ( https://www.youtube.com/watch?v=5qap5aO4i9A )。!play study我正在使用 ytdl-core-discord,但我不断收到相同的错误:

Error: Error parsing info: Unable to retrieve video metadata...

网上很多人说解决这个问题的方法就是更新ytdl,但是我今天安装了它并且完全更新了。不用说,这不会向语音频道播放任何音乐,但它会加入频道。

脚.ts:

import {MessageEmbed, Message} from 'discord.js';
import config from '../../GGBot.config.js';
import ytdl from 'ytdl-core-discord';

export default async (msg: Message) => {
    if(!msg.member?.voice.channelID){
        msg.channel.send(
            new MessageEmbed()
            .setColor(config.embedColor)
            .setTitle('You Must Be In A Voice Channel To Play Audio')
            .setThumbnail(msg.author.displayAvatarURL())
            .setDescription('Please join a voice channel to play audio')
        )
        return;
    }

    const connection = await msg.member.voice.channel?.join();
    const stream = await ytdl('w2Ov5jzm3j8', {filter:'audioonly'});
    connection?.play(stream, {seek:0, volume:1})
        .on('finish', () => msg.member?.voice.channel?.leave());
    console.log('playing')
        
}
4

2 回答 2

0

我查看了文档,我认为您不能将 ID 传递给ytdl函数,您需要使用 url。像这样的东西:"https://www.youtube.com/watch?v= ${videoId}"

编辑:这里是ytdl-core 文档的链接,因为ytdl-core-discord它只是一个包装器

于 2021-05-03T23:13:08.823 回答
0

只需添加质量选择一个从 93 到 95 的数字(它对我有用)

const connection = await msg.member.voice.channel?.join();
const stream = await ytdl('streamlink', {filter:'audioonly'}, {quality: '94'});
connection?.play(stream, {seek:0, volume:1})
.on('finish', () => msg.member?.voice.channel?.leave());
console.log('playing')
于 2021-09-06T13:16:24.057 回答