mirror of
https://github.com/gizmo4487/O-Bot.git
synced 2025-05-30 20:22:31 -05:00
Added o!voice and removed o!ping
This commit is contained in:
parent
695afa7eb7
commit
b47831b5e1
@ -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.
|
Run ``npm install`` in the bot folder to install dependencies.
|
||||||
## Commands
|
## Commands
|
||||||
* ``o!help``: Display help message
|
* ``o!help``: Display help message
|
||||||
* ``o!ping``: Test if bot is alive
|
|
||||||
* ``o!pi``: Make O speak
|
* ``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*
|
*More commands to follow*
|
||||||
|
|
||||||
|
69
o-bot.js
69
o-bot.js
@ -1,5 +1,6 @@
|
|||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const auth = require('./auth.json');
|
const auth = require('./auth.json');
|
||||||
|
var sound;
|
||||||
|
|
||||||
// Create bot object
|
// Create bot object
|
||||||
const bot = new Discord.Client({autoReconnect:true});
|
const bot = new Discord.Client({autoReconnect:true});
|
||||||
@ -8,8 +9,9 @@ const bot = new Discord.Client({autoReconnect:true});
|
|||||||
bot.once('ready', () => {
|
bot.once('ready', () => {
|
||||||
console.log('Connected');
|
console.log('Connected');
|
||||||
});
|
});
|
||||||
|
//bot.on('debug', console.log);
|
||||||
bot.on('message', message => {
|
bot.on('message', message => {
|
||||||
// Prefix is '!'
|
// Prefix is 'o!'
|
||||||
if (message.content.substring(0, 2) == 'o!') {
|
if (message.content.substring(0, 2) == 'o!') {
|
||||||
var args = message.content.substring(2).split(' ');
|
var args = message.content.substring(2).split(' ');
|
||||||
var cmd = args[0];
|
var cmd = args[0];
|
||||||
@ -18,23 +20,60 @@ bot.on('message', message => {
|
|||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
switch(cmd) {
|
switch(cmd) {
|
||||||
// o!ping
|
|
||||||
case 'ping':
|
|
||||||
message.channel.send('Pong!');
|
|
||||||
break;
|
|
||||||
|
|
||||||
// o!help
|
// o!help
|
||||||
case 'help':
|
case 'help':
|
||||||
message.channel.send('Commands:\no!help: Display this message\no!ping: Test if bot is alive\no!pi: Make O speak');
|
message.channel.send('Commands:\no!help: Display this message\no!pi: Make O speak\no!voice: Make O speak for real');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// o!pi
|
// o!pi
|
||||||
case 'pi':
|
case 'pi':
|
||||||
message.channel.send('Pipi? Pipi-pipipipipi!');
|
message.channel.send('Pipi? Pipi-pipipipipi!');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// o!voice
|
||||||
|
case 'voice':
|
||||||
|
play(message, "o_sound/ready.wav");
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
// End of command list
|
// 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);
|
bot.login(auth.token);
|
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "O-Bot",
|
"name": "O-Bot",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"description": "Pipipi-pipipipi!",
|
"description": "Pipipi-pipipipi!",
|
||||||
"main": "o-bot.js",
|
"main": "o-bot.js",
|
||||||
"author": "gizmo4487",
|
"author": "gizmo4487",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@discordjs/opus": "^0.1.0",
|
||||||
"bufferutil": "^4.0.1",
|
"bufferutil": "^4.0.1",
|
||||||
"discord.js": "^12.0.2",
|
"discord.js": "^12.0.2",
|
||||||
"erlpack": "github:discordapp/erlpack",
|
"erlpack": "github:discordapp/erlpack",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user