Sound Playing Check

This commit is contained in:
Daniel Odendahl Jr
2017-03-19 16:12:41 +00:00
parent eccd8c3c30
commit aa5029df54
+16 -7
View File
@@ -32,13 +32,22 @@ class SoundBoardCommand extends commando.Command {
} else if(soundToPlay === 'list') { } else if(soundToPlay === 'list') {
message.channel.send("**Available Sounds:** Cat, Pikachu, Vader, Doh, It's a Trap, Mario Death, Pokemon Center, Dun Dun Dun, Spongebob, Ugly Barnacle, Woo Hoo, Space, GLaDOS Bird, Airhorn, Zelda Chest"); message.channel.send("**Available Sounds:** Cat, Pikachu, Vader, Doh, It's a Trap, Mario Death, Pokemon Center, Dun Dun Dun, Spongebob, Ugly Barnacle, Woo Hoo, Space, GLaDOS Bird, Airhorn, Zelda Chest");
} else if(soundToPlay === sounds.avaliable[soundToPlay]) { } else if(soundToPlay === sounds.avaliable[soundToPlay]) {
voiceChannel.join().then(connnection => { let alreadyConnected = this.client.voiceConnections.get(voiceChannel.guild.id)
let stream = sounds.paths[soundToPlay]; if(alreadyConnected) {
let dispatcher = connnection.playStream(stream); if(alreadyConnected.channel.id === voiceChannel.id) {
dispatcher.on('end', () => { message.channel.send(':x: Error! I am already playing a sound!');
voiceChannel.leave(); } else {
}); message.channel.send(':x: Error! I am already playing a sound!');
}); }
} else {
voiceChannel.join().then(connnection => {
let stream = sounds.paths[soundToPlay];
let dispatcher = connnection.playStream(stream);
dispatcher.on('end', () => {
voiceChannel.leave();
});
});
}
} else { } else {
message.channel.send(':x: Error! Sound not found! Please use ;soundboard list to see a list of sounds you can play.'); message.channel.send(':x: Error! Sound not found! Please use ;soundboard list to see a list of sounds you can play.');
} }