aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AudioBackend.js20
-rw-r--r--commands/control.js34
-rw-r--r--commands/join.js34
-rw-r--r--commands/list.js1
4 files changed, 65 insertions, 24 deletions
diff --git a/AudioBackend.js b/AudioBackend.js
index dbc239a..070e717 100644
--- a/AudioBackend.js
+++ b/AudioBackend.js
@@ -19,7 +19,13 @@
*
***************************************************************************/
-import { createAudioPlayer, createAudioResource, joinVoiceChannel, VoiceConnectionStatus } from '@discordjs/voice'
+import {
+ createAudioPlayer,
+ createAudioResource,
+ getVoiceConnection,
+ joinVoiceChannel,
+ VoiceConnectionStatus
+} from '@discordjs/voice'
import { MessageEmbed } from 'discord.js'
import config from './config.json' assert {type: 'json'}
import fs from 'fs'
@@ -87,4 +93,16 @@ export function playAudio(bot) {
if (!statusChannel) return console.error('The status channel does not exist! Skipping.');
statusChannel.send({embeds: [statusEmbed]});
+}
+
+export function destroyAudio(interaction) {
+ fileData = "Now Playing: Nothing";
+ fs.writeFile("now-playing.txt", fileData, (err) => {
+ if (err)
+ console.log(err);
+ });
+ audio = "Not Playing";
+ player.stop();
+ const connection = getVoiceConnection(interaction.guild.id);
+ connection.destroy();
} \ No newline at end of file
diff --git a/commands/control.js b/commands/control.js
index 42c168a..50a78e7 100644
--- a/commands/control.js
+++ b/commands/control.js
@@ -20,12 +20,8 @@
***************************************************************************/
import { SlashCommandBuilder } from '@discordjs/builders'
-import { getVoiceConnection } from "@discordjs/voice";
import { MessageEmbed, MessageActionRow, MessageButton } from 'discord.js'
-import { audio, player, playAudio } from '../AudioBackend.js'
-import fs from 'fs'
-
-let fileData;
+import { audio, player, playAudio, destroyAudio } from '../AudioBackend.js'
export default {
data: new SlashCommandBuilder()
@@ -61,32 +57,24 @@ export default {
const collector = interaction.channel.createMessageComponentCollector();
- collector.on('collect', async i => {
- if (i.customId === 'play') {
+ collector.on('collect', async ctlButton => {
+ if (ctlButton.customId === 'play') {
player.unpause();
- await i.reply({content:'Resuming music', ephemeral:true})
+ await ctlButton.reply({content:'Resuming music', ephemeral:true})
}
- if (i.customId === 'pause') {
+ if (ctlButton.customId === 'pause') {
player.pause();
- await i.reply({content:'Pausing music', ephemeral:true})
+ await ctlButton.reply({content:'Pausing music', ephemeral:true})
}
- if (i.customId === 'skip') {
+ if (ctlButton.customId === 'skip') {
player.pause();
- await i.reply({content:`Skipping \`${audio}\`...`, ephemeral:true})
+ await ctlButton.reply({content:`Skipping \`${audio}\`...`, ephemeral:true})
playAudio(bot);
}
- if (i.customId === 'leave') {
- await i.reply({content:'Leaving voice channel.', ephemeral:true})
+ if (ctlButton.customId === 'leave') {
+ await ctlButton.reply({content:'Leaving voice channel.', ephemeral:true})
console.log('Leaving voice channel...');
- fileData = "Now Playing: Nothing";
- fs.writeFile("now-playing.txt", fileData, (err) => {
- if (err)
- console.log(err);
- });
- audio = "Not Playing";
- player.stop();
- const connection = getVoiceConnection(interaction.guild.id);
- connection.destroy();
+ destroyAudio(interaction);
}
});
diff --git a/commands/join.js b/commands/join.js
new file mode 100644
index 0000000..2ac15f9
--- /dev/null
+++ b/commands/join.js
@@ -0,0 +1,34 @@
+/**************************************************************************
+ *
+ * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
+ * (C) Copyright 2022
+ * Programmed by Andrew Lee
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ ***************************************************************************/
+
+import { SlashCommandBuilder } from '@discordjs/builders'
+import { voiceInit } from '../AudioBackend.js'
+import { bot } from "../bot.js";
+
+export default {
+ data: new SlashCommandBuilder()
+ .setName('join')
+ .setDescription('Joins the voice chat'),
+ async execute(interaction) {
+ interaction.reply('Joining the voice channel');
+ voiceInit(bot);
+ },
+}; \ No newline at end of file
diff --git a/commands/list.js b/commands/list.js
index 3d88ca6..00c984e 100644
--- a/commands/list.js
+++ b/commands/list.js
@@ -21,6 +21,7 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import fs from 'fs'
+
const musicFolder = './music';
export default {