Added o!voice and removed o!ping

This commit is contained in:
2020-03-15 13:17:28 -04:00
committed by GitHub
parent 695afa7eb7
commit b47831b5e1
3 changed files with 57 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
const Discord = require('discord.js');
const auth = require('./auth.json');
var sound;
// Create bot object
const bot = new Discord.Client({autoReconnect:true});
@@ -8,8 +9,9 @@ const bot = new Discord.Client({autoReconnect:true});
bot.once('ready', () => {
console.log('Connected');
});
//bot.on('debug', console.log);
bot.on('message', message => {
// Prefix is '!'
// Prefix is 'o!'
if (message.content.substring(0, 2) == 'o!') {
var args = message.content.substring(2).split(' ');
var cmd = args[0];
@@ -18,23 +20,60 @@ bot.on('message', message => {
// Commands
switch(cmd) {
// o!ping
case 'ping':
message.channel.send('Pong!');
break;
// o!help
case 'help':
message.channel.send('Commands:\no!help: Display this message\no!ping: Test if bot is alive\no!pi: Make O speak');
break;
// o!pi
case 'pi':
message.channel.send('Pipi? Pipi-pipipipipi!');
break;
// o!help
case 'help':
message.channel.send('Commands:\no!help: Display this message\no!pi: Make O speak\no!voice: Make O speak for real');
break;
// o!pi
case 'pi':
message.channel.send('Pipi? Pipi-pipipipipi!');
break;
// o!voice
case 'voice':
play(message, "o_sound/ready.wav");
break;
// End of command list
}
}
}
});
async function play(message, sound){
try{
const VC = message.member.voice.channel;
if(!message.guild){
message.channel.send("The bot cannot join private voice chats.")
}
else if(!VC){
message.channel.send("You are not in a voice channel!");
}
else if (!VC.permissionsFor(message.client.user).has('CONNECT') || !VC.permissionsFor(message.client.user).has('SPEAK')) {
message.channel.send('Missing join/speak permissions!');
}
else{
// Here we try to join the voicechat and save our connection into our object.
var connection = await VC.join();
message.channel.send("Playing!");
const dispatcher = connection.play(sound);
dispatcher.on("finish", () => {
message.channel.send("Should be disconnecting now");
dispatcher.destroy();
VC.leave();
})
.on('error', error => {
console.error(error);
});
}
} catch(error){
console.log(error);
}
}
bot.login(auth.token);