I tried making a rickroll command like this:
client.on('message', message => {
if (message.content.startsWith('music plz')) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) {
return message.reply(`Wow what a scrub, join a Voice Channel first`);
}
voiceChannel.join()
.then(connection => {
const stream = ytdl('https://www.youtube.com/watch?v=dQw4w9WgXcQ', { filter: 'audioonly' });
const dispatcher = connection.playStream(stream, streamOptions);
})
It joins the VC and gives an error when not in VC but does not play music what am I doing wrong? I use Discord.js v12.5 and I am new to
it.
Check the guide Here they have a guide of how to do this. Also please update to v13, it's much better. Something like this:
const fs = require('fs');
const broadcast = client.voice.createBroadcast();
// From a path
broadcast.play('audio.mp3');
// From a ReadableStream
broadcast.play(fs.createReadStream('audio.mp3'));
// From a URL
broadcast.play('http://myserver.com/audio.aac');