Skip to content

Commit

Permalink
[Fix] various fixes and better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Oct 1, 2021
1 parent 2a96eab commit 46acf62
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 32 deletions.
27 changes: 17 additions & 10 deletions commands/music/back.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
.setDescription("plays previous track from the queue"),

async execute(interaction, client) {
const queue = client.player.getQueue(interaction.guild);
await interaction.deferReply();
const queue = client.player.getQueue(interaction.guild);

if (!queue || !queue.playing) {
return await interaction.followUp({
Expand All @@ -27,14 +27,21 @@ module.exports = {
);
}

await queue.back();
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`Playing Previous Track **${queue.previousTracks[0].title}**, [<@${interaction.user.id}>]`
),
],
});
try {
await queue.back();
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`Playing Previous Track **${queue.previousTracks[0].title}**, [<@${interaction.user.id}>]`
),
],
});
} catch (error) {
client.logger(error.message, "error");
await interaction.followUp({
embeds: [embedMessage("#9dcc37", "Could not play the previous track")],
});
}
},
};
13 changes: 11 additions & 2 deletions commands/music/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
.setDescription("clears the music queue"),

async execute(interaction, client) {
const queue = client.player.getQueue(interaction.guild);
await interaction.deferReply();
const queue = client.player.getQueue(interaction.guild);

if (!queue) {
return await interaction.followUp({
Expand All @@ -20,6 +20,7 @@ module.exports = {
],
});
}

try {
if (queue) {
await queue.clear();
Expand All @@ -33,7 +34,15 @@ module.exports = {
});
}
} catch (err) {
console.error(err);
client.logger(err.message, "error");
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
"Could not clear the queue, maybe there is no queue"
),
],
});
}
},
};
12 changes: 10 additions & 2 deletions commands/music/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
.setDescription("disconnects from the channel"),

async execute(interaction, client) {
const queue = client.player.getQueue(interaction.guild);
await interaction.deferReply();
const queue = client.player.getQueue(interaction.guild);

if (!queue) {
return await interaction.followUp({
Expand All @@ -31,7 +31,15 @@ module.exports = {
});
}
} catch (err) {
console.error(err);
client.logger(err.message, "error");
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
"Could not disconnect the bot, Maybe you do not have permission ?"
),
],
});
}
},
};
2 changes: 1 addition & 1 deletion commands/music/lyrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
),
],
});
console.error(error);
client.logger(error.message, "error");
}
},
};
2 changes: 1 addition & 1 deletion commands/music/nowPlaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
.setDescription("shows the current music name"),

async execute(interaction, client) {
const queue = client.player.getQueue(interaction.guild);
await interaction.deferReply();
const queue = client.player.getQueue(interaction.guild);

if (!queue || !queue.playing) {
return await interaction.followUp({
Expand Down
7 changes: 5 additions & 2 deletions commands/music/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
.setDescription("pauses the song"),

async execute(interaction, client) {
const queue = client.player.getQueue(interaction.guild);
await interaction.deferReply();
const queue = client.player.getQueue(interaction.guild);

if (!queue || !queue.playing)
return await interaction.followUp({
Expand All @@ -30,7 +30,10 @@ module.exports = {
});
}
} catch (err) {
console.error(err);
client.logger(err.message, "error");
await interaction.followUp({
embeds: [embedMessage("#9dcc37", "Could not pause the song")],
});
}
},
};
3 changes: 1 addition & 2 deletions commands/music/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ module.exports = {
});

const queue = client.player.createQueue(interaction.guildId, {
metadata: interaction,
leaveOnEnd: false,
leaveOnStop: true,
initialVolume: 80,
Expand Down Expand Up @@ -117,7 +116,7 @@ module.exports = {
embeds: [musicEmbed],
});
} catch (err) {
console.log(err);
client.logger(err.message, "error");
await interaction.followUp(
"There was an error playing this song, please try again"
);
Expand Down
7 changes: 5 additions & 2 deletions commands/music/resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
.setDescription("resumes the song"),

async execute(interaction, client) {
const queue = client.player.getQueue(interaction.guild);
await interaction.deferReply();
const queue = client.player.getQueue(interaction.guild);

if (!queue || !queue.playing)
return await interaction.followUp({
Expand All @@ -30,7 +30,10 @@ module.exports = {
});
}
} catch (err) {
console.error(err);
client.logger(err.message, "error");
await interaction.followUp({
embeds: [embedMessage("#9dcc37", "I was not able to resume this song")],
});
}
},
};
23 changes: 15 additions & 8 deletions commands/music/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ module.exports = {
embeds: [embedMessage("#9dcc37", `❌ | There is no queue to shuffle!`)],
});

if (queue) {
await queue.shuffle();
try {
if (queue) {
await queue.shuffle();
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ Queue has been shuffled [<@${interaction.user.id}>]`
),
],
});
}
} catch (error) {
client.logger(error.message, "error");
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ Queue has been shuffled [<@${interaction.user.id}>]`
),
],
embeds: [embedMessage("#9dcc37", "Could not shuffle the queue")],
});
}
},
Expand Down
5 changes: 4 additions & 1 deletion commands/music/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ module.exports = {
],
});
} catch (err) {
console.error(err);
client.logger(err.message, "error");
await interaction.followUp({
embeds: [embedMessage("#9dcc37", "Song could not be skipped")],
});
}
},
};
3 changes: 2 additions & 1 deletion commands/music/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {

try {
if (queue && queue.playing) {
await queue.stop();
await interaction.followUp({
embeds: [
embedMessage(
Expand All @@ -31,9 +32,9 @@ module.exports = {
),
],
});
await queue.stop();
}
} catch (err) {
client.logger(err.message, "error");
await interaction.followUp({
embeds: [embedMessage("#9dcc37", `❌ | Something went wrong :/`)],
});
Expand Down

0 comments on commit 46acf62

Please sign in to comment.