Files
xiao/commands/random/soundboard.js
T
Daniel Odendahl Jr 14f85f94bd 22.0.0
2017-06-01 08:44:02 +00:00

62 lines
2.4 KiB
JavaScript

const Command = require('../../structures/Command');
const { names, paths } = require('../../assets/json/soundboard');
const path = require('path');
module.exports = class SoundboardCommand extends Command {
constructor(client) {
super(client, {
name: 'soundboard',
aliases: ['sound'],
group: 'random',
memberName: 'soundboard',
description: 'Plays a sound in your voice channel.',
details: `**Sounds:** ${names.join(', ')}`,
guildOnly: true,
throttling: {
usages: 1,
duration: 15
},
clientPermissions: ['ADD_REACTIONS'],
args: [
{
key: 'sound',
prompt: 'What sound would you like to play?',
type: 'string',
validate: (sound) => {
if (names.includes(sound.toLowerCase())) {
return true;
} else {
return 'Invalid Sound. Use `help soundboard` for a list of sounds.';
}
},
parse: (sound) => sound.toLowerCase()
}
]
});
}
async run(msg, args) {
const voiceChannel = msg.member.voiceChannel;
if (!voiceChannel) {
return msg.say('Please enter a Voice Channel first.');
} else if (!voiceChannel.permissionsFor(this.client.user).has('CONNECT')) {
return msg.say('This Command requires the `CONNECT` Permission.');
} else if (!voiceChannel.permissionsFor(this.client.user).has('SPEAK')) {
return msg.say('This Command requires the `SPEAK` Permission.');
} else if (!voiceChannel.joinable) {
return msg.say('This Voice Channel is not joinable.');
} else if (this.client.voiceConnections.get(voiceChannel.guild.id)) {
return msg.say('I am already playing a sound.');
}
const { sound } = args;
const connection = await voiceChannel.join();
msg.react('🔊');
const dispatcher = connection.playFile(path.join(__dirname, '..', '..', 'assets', 'sounds', paths[sound]));
dispatcher.on('end', () => {
voiceChannel.leave();
msg.react('✅');
return null;
});
}
};