aboutsummaryrefslogtreecommitdiff
path: root/bot.js
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2022-03-26 21:07:35 -0400
committerAndrew Lee <alee14498@protonmail.com>2022-03-26 21:07:35 -0400
commitae48ba2014bca4a10adf8cf8b6fb0d9e6d4ff401 (patch)
tree38fbe09fa9c7b93d708ed477ea84f7cc0a8ec17a /bot.js
parent99c86c80788990e5b8adafeb3b9ba5f863fba855 (diff)
downloadDLAP-ae48ba2014bca4a10adf8cf8b6fb0d9e6d4ff401.tar.gz
DLAP-ae48ba2014bca4a10adf8cf8b6fb0d9e6d4ff401.tar.bz2
DLAP-ae48ba2014bca4a10adf8cf8b6fb0d9e6d4ff401.zip
Audio stuff is now on its own file
Diffstat (limited to 'bot.js')
-rw-r--r--bot.js86
1 files changed, 15 insertions, 71 deletions
diff --git a/bot.js b/bot.js
index 9aaeed7..98505c4 100644
--- a/bot.js
+++ b/bot.js
@@ -20,76 +20,16 @@
***************************************************************************/
const { Client, MessageEmbed, Collection, version } = require('discord.js');
const fs = require('fs');
-const { join } = require('node:path');
-const { createAudioPlayer, createAudioResource, joinVoiceChannel, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice');
+const { getVoiceConnection } = require('@discordjs/voice');
const bot = new Client({intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES']});
const config = require('./config.json');
-const player = createAudioPlayer();
+const AudioBackend = require('./AudioBackend');
let audio;
let fileData;
let txtFile = true;
bot.login(config.token);
-function voiceInit() {
- bot.channels.fetch(config.voiceChannel).then(channel => {
- const connection = joinVoiceChannel({
- channelId: channel.id,
- guildId: channel.guild.id,
- adapterCreator: channel.guild.voiceAdapterCreator
- });
-
- connection.on(VoiceConnectionStatus.Ready, () => {
- console.log('Ready to blast music!');
- });
-
- connection.on(VoiceConnectionStatus.Destroyed, () => {
- console.log('Destroying beats...');
- });
-
- player.on('idle', () => {
- console.log("Music has finished playing, shuffling music...")
- playAudio();
- })
-
- playAudio();
- connection.subscribe(player);
- })
-}
-
-function playAudio() {
- let files = fs.readdirSync(join(__dirname,'music'));
-
- while (true) {
- audio = files[Math.floor(Math.random() * files.length)];
- console.log('Searching .mp3 file...');
- if (audio.endsWith('.mp3')) {
- break;
- }
- }
-
- let resource = createAudioResource(join(__dirname, 'music/' + audio));
-
- player.play(resource);
-
- console.log('Now playing: ' + audio);
- if (txtFile === true) {
- fileData = "Now Playing: " + audio;
- fs.writeFile("now-playing.txt", fileData, (err) => {
- if (err)
- console.log(err);
- });
- }
- const statusEmbed = new MessageEmbed()
- .addField('Now Playing', `${audio}`)
- .setColor('#0066ff')
-
- let statusChannel = bot.channels.cache.get(config.statusChannel);
- if (!statusChannel) return console.error('The status channel does not exist! Skipping.');
- statusChannel.send({embeds: [statusEmbed]});
-
-}
-
// Slash Command Handler
bot.commands = new Collection();
@@ -105,9 +45,11 @@ bot.once('ready', () => {
console.log(`Logged in as ${bot.user.tag}!`);
console.log(`Running on Discord.JS ${version}`)
console.log(`Prefix: ${config.prefix}`);
- console.log(`Owner ID: ${config.botOwner}`);
console.log(`Voice Channel: ${config.voiceChannel}`);
- console.log(`Status Channel: ${config.statusChannel}\n`);
+ console.log(`Status Channel: ${config.statusChannel}`);
+ console.log(`Owner ID: ${config.botOwner}`);
+ console.log(`Guild ID: ${config.guildID}`);
+ console.log(`Client ID: ${config.clientID}\n`);
// Set bots' presence
bot.user.setPresence({
@@ -131,7 +73,9 @@ bot.once('ready', () => {
if (!statusChannel) return console.error('The status channel does not exist! Skipping.');
statusChannel.send({ embeds: [readyEmbed]});
- voiceInit();
+ //voiceInit();
+
+ AudioBackend(bot, config);
});
@@ -194,23 +138,23 @@ bot.on('messageCreate', async msg => {
if (command === 'join') {
msg.reply('Joining voice channel.');
- voiceInit();
+ //voiceInit();
}
if (command === 'resume') {
msg.reply('Resuming music.');
- player.unpause();
+ //player.unpause();
}
if (command === 'pause') {
msg.reply('Pausing music.');
- player.pause();
+ //player.pause();
}
if (command === 'skip') {
msg.reply('Skipping `' + audio + '`...');
- player.pause()
- playAudio();
+ //player.pause()
+ //playAudio();
}
if (command === 'leave') {
@@ -224,7 +168,7 @@ bot.on('messageCreate', async msg => {
});
}
audio = "Not Playing";
- player.stop();
+ //player.stop();
const connection = getVoiceConnection(msg.guild.id);
connection.destroy();