Reputation: 79
I'm trying to make a music bot in Javascript and I'm trying to figure out how to make it play a link. I've tried a lot of things but it doesn't work. Here's my code:
}
else if(command === prefix + 'play'){
const song = message.content.first
const connection = await message.member.voice.channel.join();
connection.play(ytdl(https://www.youtube.com/watch?v=X-NMn5H4hXU&t=4s, { filter: '' }));
}
Upvotes: -1
Views: 3780
Reputation: 2837
Did you forget to put quotation marks around your string like this?
connection.play(ytdl("https://www.youtube.com/watch?v=X-NMn5H4hXU&t=4s", { filter: '' }));
If that does not fix your problem, you can try to use ytdl-core with ytdl-core-discord if you are not using them already. That's what I use in my bot.
For discord.js 12.x:
const ytdl = require("ytdl-core-discord");
/* ... connection defined somewhere ... */
connection.play(await ytdl("https://www.youtube.com/watch?v=X-NMn5H4hXU&t=4s"), { type: "opus" });
For discord.js 12.x (without await):
const ytdl = require("ytdl-core-discord");
/* ... connection defined somewhere ... */
ytdl("https://www.youtube.com/watch?v=X-NMn5H4hXU&t=4s").then((stream) => {
connection.play(stream, { type: "opus" });
});
For discord.js 11.4.x:
const ytdl = require("ytdl-core-discord");
/* ... connection defined somewhere ... */
connection.playOpusStream(await ytdl("https://www.youtube.com/watch?v=X-NMn5H4hXU&t=4s"));
Upvotes: 3