Added o!voice and removed o!ping

This commit is contained in:
Max Gorley 2020-03-15 13:17:28 -04:00 committed by GitHub
parent 695afa7eb7
commit b47831b5e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 17 deletions

View File

@ -7,8 +7,8 @@ A Discord bot themed around O, a character in SEGA's Puyo Puyo Tetris
Run ``npm install`` in the bot folder to install dependencies.
## Commands
* ``o!help``: Display help message
* ``o!ping``: Test if bot is alive
* ``o!pi``: Make O speak
* ``o!voice``: O-Bot will join a voice channel and play one of O's voice lines, then leave
*More commands to follow*

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);

View File

@ -1,10 +1,11 @@
{
"name": "O-Bot",
"version": "0.0.1",
"version": "0.0.2",
"description": "Pipipi-pipipipi!",
"main": "o-bot.js",
"author": "gizmo4487",
"dependencies": {
"@discordjs/opus": "^0.1.0",
"bufferutil": "^4.0.1",
"discord.js": "^12.0.2",
"erlpack": "github:discordapp/erlpack",