2020-07-19 15:32:22 -04:00
|
|
|
/*********************************************
|
|
|
|
*
|
|
|
|
* Project Jul-2020 Discord Bot
|
|
|
|
* By: Andrew Lee
|
|
|
|
*
|
|
|
|
* Licensed with GPL-3.0
|
|
|
|
*
|
|
|
|
*********************************************/
|
2020-07-18 19:28:42 -04:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
const client = new Discord.Client();
|
|
|
|
const config = require('./token.json');
|
2020-07-19 13:42:52 -04:00
|
|
|
var prefix = "!";
|
2020-07-19 12:59:04 -04:00
|
|
|
var voiceChannel = "734184921433899108";
|
2020-07-18 19:28:42 -04:00
|
|
|
|
2020-07-19 13:42:52 -04:00
|
|
|
function playAudio() {
|
2020-07-19 12:59:04 -04:00
|
|
|
const channel = client.channels.cache.get(voiceChannel);
|
|
|
|
if (!channel) return console.error("The channel does not exist!");
|
|
|
|
channel.join().then(connection => {
|
|
|
|
console.log("Successfully connected to this channel.");
|
2020-07-19 13:10:39 -04:00
|
|
|
connection.play('./music/4616-werq-by-kevin-macleod.mp3');
|
2020-07-19 12:59:04 -04:00
|
|
|
}).catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
});
|
2020-07-19 13:42:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
client.on('ready', () => {
|
|
|
|
console.log(`Logged in as ${client.user.tag}!`);
|
|
|
|
console.log(`Prefix: ${prefix}`);
|
2020-07-19 14:08:42 -04:00
|
|
|
client.user.setStatus("invisible");
|
2020-07-19 13:42:52 -04:00
|
|
|
playAudio();
|
2020-07-18 19:28:42 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
client.on('message', async msg => {
|
|
|
|
if (!['242775871059001344'].includes(msg.author.id)) return;
|
2020-07-19 18:56:43 -04:00
|
|
|
const args = msg.content.slice(prefix.length).trim().split(/ +/g);
|
2020-07-18 19:28:42 -04:00
|
|
|
if (!msg.guild) return;
|
|
|
|
if (msg.author.bot) return;
|
|
|
|
if (!msg.content.startsWith(prefix)) return;
|
|
|
|
|
|
|
|
let command = msg.content.split(" ")[0];
|
|
|
|
command = command.slice(prefix.length);
|
|
|
|
|
|
|
|
if (command == 'ping') {
|
2020-07-19 14:08:42 -04:00
|
|
|
msg.reply('Pong!');
|
2020-07-18 19:28:42 -04:00
|
|
|
}
|
2020-07-18 20:45:06 -04:00
|
|
|
|
2020-07-19 14:08:42 -04:00
|
|
|
if (command == 'stop') {
|
|
|
|
await msg.reply("Powering off...")
|
|
|
|
console.log("Powering off...");
|
|
|
|
client.destroy();
|
|
|
|
process.exit(0);
|
2020-07-18 19:28:42 -04:00
|
|
|
}
|
2020-07-18 20:45:06 -04:00
|
|
|
|
|
|
|
if (command == 'join') {
|
2020-07-18 19:28:42 -04:00
|
|
|
// Only try to join the sender's voice channel if they are in one themselves
|
2020-07-19 13:42:52 -04:00
|
|
|
playAudio();
|
2020-07-18 19:28:42 -04:00
|
|
|
}
|
2020-07-18 21:08:54 -04:00
|
|
|
if (command == 'skip') {
|
|
|
|
//TODO
|
|
|
|
}
|
2020-07-18 20:45:06 -04:00
|
|
|
if (command == 'leave') {
|
2020-07-18 19:28:42 -04:00
|
|
|
// Only try to join the sender's voice channel if they are in one themselves
|
|
|
|
if (msg.member.voice.channel) {
|
2020-07-18 20:45:06 -04:00
|
|
|
console.log("Disconnected from voice chat...")
|
2020-07-18 19:28:42 -04:00
|
|
|
const connection = await msg.member.voice.channel.leave();
|
|
|
|
} else {
|
|
|
|
msg.reply('You need to join a voice channel first!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
client.login(config.token);
|