Catch errors in soundboard

This commit is contained in:
Daniel Odendahl Jr
2017-09-09 01:20:16 +00:00
parent 7a38399ac9
commit 631e312fe3
2 changed files with 12 additions and 15 deletions
+8 -11
View File
@@ -17,7 +17,6 @@ module.exports = class SoundboardCommand extends Command {
usages: 1,
duration: 30
},
clientPermissions: ['ADD_REACTIONS'],
args: [
{
key: 'sound',
@@ -41,19 +40,17 @@ module.exports = class SoundboardCommand extends Command {
if (!channel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) {
return msg.say('Missing the "Connect" or "Speak" permission for the voice channel.');
}
if (!channel.joinable) return msg.say('Your Voice Channel is not joinable.');
if (!channel.joinable) return msg.say('Your voice channel is not joinable.');
if (this.client.voiceConnections.has(channel.guild.id)) return msg.say('I am already playing a sound.');
try {
const connection = await channel.join();
await msg.react('🔊');
const dispatcher = connection.playFile(path.join(__dirname, '..', '..', 'assets', 'sounds', `${sound}.mp3`));
dispatcher.once('end', () => {
channel.leave();
msg.react('✅');
});
dispatcher.once('error', () => {
channel.leave();
msg.react('⚠');
});
dispatcher.once('end', () => channel.leave());
dispatcher.once('error', () => channel.leave());
return null;
} catch (err) {
await channel.leave();
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "38.0.0",
"version": "38.0.1",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {