Explanation
I have this code that plays youtube video audio in voice channels.
When it joins the channel I get an error that says "ffmpeg not found". I ran the terminal command "npm i ffmpeg-static" and it worked fine but after a couple of minutes I get a long error and the music stops playing.
This is my code:
client.on("ready", async () => {
for (const channelId of Channels) {
joinChannel(channelId);
await new Promise(res => setTimeout(()=>res(2), 500))
}
function joinChannel(channelId) {
client.channels.fetch(channelId).then(channel => {
const VoiceConnection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator
});
const resource = createAudioResource(ytdl("https://youtu.be/0J2gdL87fVs", {
filter: "audioonly"
}), {
inlineVolume: true
});
resource.volume.setVolume(0.2);
const player = createAudioPlayer()
VoiceConnection.subscribe(player);
player.play(resource);
player.on("idle", () => {
try {
player.stop()
}catch (e) {}
try {
VoiceConnection.destory()
}catch (e) {}
joinChannel(channelId)
})
}).catch(console.error)
}
})