Skip to content

Commit

Permalink
[New] Using play-dl instead of yt-dl to reduce playback issues and ab…
Browse files Browse the repository at this point in the history
…orts
  • Loading branch information
naseif committed Sep 30, 2021
1 parent 6e4343b commit adad039
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions commands/music/play.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { SlashCommandBuilder, time } = require("@discordjs/builders");
const { SlashCommandBuilder } = require("@discordjs/builders");
const { embedMessage } = require("../../modules/embedSimple");
const playdl = require("play-dl");

module.exports = {
data: new SlashCommandBuilder()
Expand Down Expand Up @@ -32,20 +33,7 @@ module.exports = {
],
});

const guild = client.guilds.cache.get(interaction.guildId);

const songString = interaction.options.getString("song");

const searchSong = await client.player.search(songString, {
requestedBy: interaction.user,
});

if (!searchSong.tracks.length || !searchSong)
return interaction.followUp({
embeds: [embedMessage("#9dcc37", `❌ | Song not found`)],
});

const queue = client.player.createQueue(guild, {
const queue = client.player.createQueue(interaction.guildId, {
metadata: interaction,
leaveOnEnd: false,
leaveOnStop: true,
Expand All @@ -58,8 +46,23 @@ module.exports = {
},
bufferingTimeout: 200,
leaveOnEmpty: true,
async onBeforeCreateStream(track, source, _queue) {
if (source === "youtube") {
return (await playdl.stream(track.url)).stream;
}
},
});

const songString = interaction.options.getString("song");
const searchSong = await client.player.search(songString, {
requestedBy: interaction.user,
});

if (!searchSong.tracks.length || !searchSong)
return interaction.followUp({
embeds: [embedMessage("#9dcc37", `❌ | Song not found`)],
});

try {
if (!queue.connection)
await queue.connect(interaction.member.voice.channel);
Expand Down Expand Up @@ -119,6 +122,7 @@ module.exports = {
embeds: [musicEmbed],
});
} catch (err) {
console.log(err);
await interaction.followUp(
"There was an error playing this song, please try again"
);
Expand Down

0 comments on commit adad039

Please sign in to comment.