Recently, I've been experimenting with creating a custom Discord bot as a way to have some fun and help out my friends. One of the features I'm trying to implement is streaming a live video in a voice chat whenever someone uses the !play study
command. However, I keep encountering the same frustrating error message when using ytdl-core-discord:
Error: Error parsing info: Unable to retrieve video metadata...
After doing some research, many suggest that updating ytdl should fix this issue. Despite installing it today and confirming that it's up-to-date, I still can't get the music to play in the voice channel, even though the bot successfully joins the channel.
Here's a snippet from my code (foo.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')
}