Skip to content

Commit

Permalink
Error catching & extra ytdl buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
eritislami committed Apr 28, 2020
1 parent 8cff648 commit 0cd74f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion commands/play.js
@@ -1,4 +1,3 @@
const { Util } = require("discord.js");
const { play } = require("../include/play");
const { YOUTUBE_API_KEY } = require("../config.json");
const ytdl = require("ytdl-core");
Expand Down
24 changes: 15 additions & 9 deletions include/play.js
Expand Up @@ -11,10 +11,7 @@ module.exports = {
}

try {
var stream = await ytdlDiscord(song.url, {
filter: "audioonly",
quality: "highestaudio"
});
var stream = await ytdlDiscord(song.url, { highWaterMark: 1 << 25 });
} catch (error) {
if (queue) {
queue.songs.shift();
Expand Down Expand Up @@ -45,7 +42,11 @@ module.exports = {
module.exports.play(queue.songs[0], message);
}
})
.on("error", console.error);
.on("error", err => {
console.error(err);
queue.songs.shift();
module.exports.play(queue.songs[0], message);
});
dispatcher.setVolumeLogarithmic(queue.volume / 100);

try {
Expand All @@ -60,7 +61,9 @@ module.exports = {
}

const filter = (reaction, user) => user.id !== message.client.user.id;
const collector = playingMessage.createReactionCollector(filter, { time: 1800000 });
const collector = playingMessage.createReactionCollector(filter, {
time: song.duration > 0 ? song.duration * 1000 : 600000
});

collector.on("collect", (reaction, user) => {
// Stop if there is no queue on the server
Expand All @@ -71,7 +74,6 @@ module.exports = {
queue.connection.dispatcher.end();
queue.textChannel.send(`${user} ⏩ skipped the song`).catch(console.error);
collector.stop();
playingMessage.reactions.removeAll();
break;

case "⏸":
Expand Down Expand Up @@ -100,10 +102,14 @@ module.exports = {

case "⏹":
queue.songs = [];
queue.connection.dispatcher.end();
queue.textChannel.send(`${user} ⏹ stopped the music!`).catch(console.error);
try {
queue.connection.dispatcher.end();
} catch (error) {
console.error(error);
queue.connection.disconnect();
}
collector.stop();
playingMessage.reactions.removeAll();
break;

default:
Expand Down

0 comments on commit 0cd74f0

Please sign in to comment.