Skip to content

Commit

Permalink
[Fix] Error handling for all commands to prevent the bot from crashin…
Browse files Browse the repository at this point in the history
…g if something goes wrong
  • Loading branch information
naseif committed Aug 29, 2021
1 parent 8bbed18 commit 5b6dc67
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 70 deletions.
25 changes: 14 additions & 11 deletions commands/music/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ module.exports = {
],
});
}

if (queue) {
await queue.clear();
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ Queue Cleared! [<@${interaction.user.id}>]`
),
],
});
try {
if (queue) {
await queue.clear();
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ Queue Cleared! [<@${interaction.user.id}>]`
),
],
});
}
} catch (err) {
console.error(err);
}
},
};
29 changes: 15 additions & 14 deletions commands/music/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ module.exports = {
if (!queue) {
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`❌ I am not connected to a voice channel!`
),
embedMessage("#9dcc37", `❌ I am not connected to a voice channel!`),
],
});
}

if (queue) {
await queue.destroy(true);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ **${interaction.client.user.username}** disconnected from [<#${interaction.member.voice.channelId}>]`
),
],
});
try {
if (queue) {
await queue.destroy(true);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ **${interaction.client.user.username}** disconnected from [<#${interaction.member.voice.channelId}>]`
),
],
});
}
} catch (err) {
console.error(err);
}
},
};
29 changes: 15 additions & 14 deletions commands/music/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ module.exports = {
if (!queue || !queue.playing)
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`❌ | There is nothing playing to pause!`
),
embedMessage("#9dcc37", `❌ | There is nothing playing to pause!`),
],
});

if (queue) {
await queue.setPaused(true);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ **${queue.current.title}** paused [<@${interaction.user.id}>]`
),
],
});
try {
if (queue) {
await queue.setPaused(true);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ **${queue.current.title}** paused [<@${interaction.user.id}>]`
),
],
});
}
} catch (err) {
console.error(err);
}
},
};
5 changes: 1 addition & 4 deletions commands/music/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ module.exports = {
await queue.setRepeatMode(Number(mode));
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ | Autoplay mode has been enabled `
),
embedMessage("#9dcc37", `✅ | Autoplay mode has been enabled `),
],
});
break;
Expand Down
29 changes: 15 additions & 14 deletions commands/music/resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ module.exports = {
if (!queue || !queue.playing)
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`❌ | There is nothing playing to resume!`
),
embedMessage("#9dcc37", `❌ | There is nothing playing to resume!`),
],
});

if (queue) {
await queue.setPaused(false);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ **${queue.current.title}** resumed [<@${interaction.user.id}>]`
),
],
});
try {
if (queue) {
await queue.setPaused(false);
await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`✅ **${queue.current.title}** resumed [<@${interaction.user.id}>]`
),
],
});
}
} catch (err) {
console.error(err);
}
},
};
4 changes: 1 addition & 3 deletions commands/music/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ module.exports = {

if (!queue)
return await interaction.followUp({
embeds: [
embedMessage("#9dcc37", `❌ | There is no queue to shuffle!`),
],
embeds: [embedMessage("#9dcc37", `❌ | There is no queue to shuffle!`)],
});

if (queue) {
Expand Down
24 changes: 14 additions & 10 deletions commands/music/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ module.exports = {
],
});

const currnetSong = queue.current;
await queue.skip();
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`Skipped **${currnetSong.title}**, [<@${interaction.user.id}>]`
),
],
});
try {
const currnetSong = queue.current;
await queue.skip();
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`Skipped **${currnetSong.title}**, [<@${interaction.user.id}>]`
),
],
});
} catch (err) {
console.error(err);
}
},
};

0 comments on commit 5b6dc67

Please sign in to comment.