aboutsummaryrefslogtreecommitdiff
path: root/AudioBackend.js
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2022-03-29 20:41:38 -0400
committerAndrew Lee <alee14498@protonmail.com>2022-03-29 20:41:38 -0400
commitfd89e36490da711ba611c1f7c8dda93a3de054f0 (patch)
treee8c1114add718665c75bb90e7af90a9f38101815 /AudioBackend.js
parent84b7017c7016aea12339ec4a3ef2ba1bf0fb3872 (diff)
downloadDLAP-fd89e36490da711ba611c1f7c8dda93a3de054f0.tar.gz
DLAP-fd89e36490da711ba611c1f7c8dda93a3de054f0.tar.bz2
DLAP-fd89e36490da711ba611c1f7c8dda93a3de054f0.zip
New command; Every Discord interation is async
Diffstat (limited to 'AudioBackend.js')
-rw-r--r--AudioBackend.js33
1 files changed, 21 insertions, 12 deletions
diff --git a/AudioBackend.js b/AudioBackend.js
index 6507716..5960f3e 100644
--- a/AudioBackend.js
+++ b/AudioBackend.js
@@ -32,10 +32,11 @@ import fs from 'fs'
export const player = createAudioPlayer();
export let audio;
+export let files = fs.readdirSync('music');
let fileData;
-export function voiceInit(bot) {
- bot.channels.fetch(config.voiceChannel).then(channel => {
+export async function voiceInit(bot) {
+ bot.channels.fetch(config.voiceChannel).then(async channel => {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
@@ -52,17 +53,15 @@ export function voiceInit(bot) {
player.on('idle', () => {
console.log("Music has finished playing, shuffling the beats...")
- playAudio(bot);
+ searchAudio(bot);
})
- playAudio(bot);
- connection.subscribe(player);
+ await searchAudio(bot);
+ return connection.subscribe(player);
}).catch(e => { console.error("The voice channel does not exist!\\n(Have you looked at your configuration?)") })
}
-export function playAudio(bot) {
- let files = fs.readdirSync('music');
-
+export async function searchAudio(bot){
//TODO: Eventually this system will need a rework so it won't repeat the same files.
while (true) {
@@ -73,9 +72,19 @@ export function playAudio(bot) {
}
}
+ return await playAudio(bot);
+}
+
+export async function inputAudio(bot, integer) {
+ audio = files[integer]
+
+ return await playAudio(bot);
+}
+
+export async function playAudio(bot) {
let resource = createAudioResource('music/' + audio);
- player.play(resource);
+ await player.play(resource);
console.log('Now playing: ' + audio);
@@ -93,7 +102,7 @@ export function playAudio(bot) {
let statusChannel = bot.channels.cache.get(config.statusChannel);
if (!statusChannel) return console.error('The status channel does not exist! Skipping.');
- statusChannel.send({embeds: [statusEmbed]});
+ return await statusChannel.send({embeds: [statusEmbed]});
}
@@ -110,7 +119,7 @@ export function destroyAudio(interaction) {
audio = "Not Playing";
player.stop();
const connection = getVoiceConnection(interaction.guild.id);
- connection.destroy();
+ return connection.destroy();
}
export async function stopBot(bot, interaction) {
@@ -125,5 +134,5 @@ export async function stopBot(bot, interaction) {
console.log('Powering off...');
destroyAudio(interaction);
bot.destroy();
- process.exit(0);
+ return process.exit(0);
} \ No newline at end of file