diff --git a/.gitignore b/.gitignore index 703876e..3b49509 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ config.json node_modules yarn.lock -music/*.mp3 +music package-lock.json now-playing.txt .idea/ \ No newline at end of file diff --git a/AudioBackend.js b/AudioBackend.js index 5960f3e..d7b6852 100644 --- a/AudioBackend.js +++ b/AudioBackend.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * @@ -64,20 +64,12 @@ export async function voiceInit(bot) { export async function searchAudio(bot){ //TODO: Eventually this system will need a rework so it won't repeat the same files. - while (true) { - audio = files[Math.floor(Math.random() * files.length)]; - console.log('Searching .mp3 file...'); - if (audio.endsWith('.mp3')) { - break; - } - } - + audio = files[Math.floor(Math.random() * files.length)]; return await playAudio(bot); } export async function inputAudio(bot, integer) { - audio = files[integer] - + audio = files[integer]; return await playAudio(bot); } @@ -86,6 +78,7 @@ export async function playAudio(bot) { await player.play(resource); + audio = audio.split('.').slice(0, -1).join('.'); console.log('Now playing: ' + audio); if (config.txtFile === true) { @@ -107,7 +100,6 @@ export async function playAudio(bot) { } export function destroyAudio(interaction) { - if (config.txtFile === true) { fileData = "Now Playing: Nothing"; fs.writeFile("now-playing.txt", fileData, (err) => { diff --git a/README.md b/README.md index a6d150c..fd69454 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# DLMP3 Bot (Discord.JS Local MP3) +# DLAP Bot (Discord.JS Local Audio Player) -A Discord bot that plays local MP3 audio tracks. Written in Discord.JS. +A Discord bot that plays local audio tracks. Written in Discord.JS. [Video Tutorial](https://www.youtube.com/watch?v=7X3FAhYW31I) @@ -20,9 +20,11 @@ Make a new file called `config.json`. } ``` -Add your own audio files using the mp3 file extension to the `music` folder. +Create the `music` folder. -Deploy the commands by doing `node deploy-command.js` +Add your own audio files to the `music` folder. + +Deploy the commands by doing `node deploy-command.js`. Launch the bot using `node bot.js` in terminal. @@ -48,7 +50,7 @@ stop - Stops bot. # Forking When forking the project, you can make your own version of DLMP3 or help contribute to the project (See the "Contributing" section). -But you need to edit `/commands/about.js` to uncomment the `.addField('Forked by', '[your name] (discord#0000)')` section. +You need to edit `/commands/about.js` to uncomment the `.addField('Forked by', '[your name] (discord#0000)')` section. Be sure to replace that with your name. diff --git a/bot.js b/bot.js index 6978ea7..300b7e0 100644 --- a/bot.js +++ b/bot.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLMP3 Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * @@ -18,18 +18,27 @@ * along with this program. If not, see . * ***************************************************************************/ -import { Client, MessageEmbed, Collection, version } from "discord.js" -import { voiceInit } from "./AudioBackend.js" -import fs from "fs" -import config from './config.json' assert {type: 'json'} +import { Client, MessageEmbed, Collection, version } from 'discord.js' +import { voiceInit } from './AudioBackend.js' +import fs from 'fs' +import config from './config.json' assert { type: 'json' } +import path from 'path' export const bot = new Client({intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES']}); +const dir = './music'; -bot.login(config.token); +if (fs.existsSync(dir)) { + console.log('Music folder detected'); + bot.login(config.token); +} else { + console.log('Directory not found. Creating music folder...'); + console.log('Insert your beats to that folder.'); + fs.mkdirSync(dir); + process.exit(0); +} /** * Project Ideas: - * Play directly the MP3 file * New queue system * List MP3 files * Shuffle or "Play by order" mode diff --git a/commands/about.js b/commands/about.js index 55ef011..bd54e25 100644 --- a/commands/about.js +++ b/commands/about.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * @@ -21,6 +21,7 @@ import { SlashCommandBuilder } from '@discordjs/builders' import { MessageEmbed, version, MessageActionRow, MessageButton } from 'discord.js' +import npmPackage from '../package.json' assert { type:'json' } export default { data: new SlashCommandBuilder() @@ -30,6 +31,7 @@ export default { const aboutEmbed = new MessageEmbed() .setAuthor({name:`About ${bot.user.username}`, iconURL:bot.user.avatarURL()}) .addField('Information', 'A Discord bot that plays local MP3 audio tracks.') + .addField('Version', npmPackage.version) .addField('Original Creator', 'Andrew Lee (Alee#4277)') //.addField('Contributors', '[your name] (discord#0000)') //.addField('Forked by', '[your name] (discord#0000)') diff --git a/commands/control.js b/commands/control.js index f221898..83f603f 100644 --- a/commands/control.js +++ b/commands/control.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * @@ -21,7 +21,7 @@ import { SlashCommandBuilder } from '@discordjs/builders' import { MessageEmbed, MessageActionRow, MessageButton } from 'discord.js' -import {audio, player, destroyAudio, voiceInit, stopBot, searchAudio} from '../AudioBackend.js' +import { audio, player, destroyAudio, voiceInit, stopBot, searchAudio } from '../AudioBackend.js' import config from '../config.json' assert {type: 'json'} export let controlEmbed @@ -42,11 +42,11 @@ export default { const controlButtons = new MessageActionRow() .addComponents( new MessageButton() - .setStyle('SECONDARY') + .setStyle('SUCCESS') .setLabel('Join') .setCustomId('join'), new MessageButton() - .setStyle('SUCCESS') + .setStyle('PRIMARY') .setLabel('Play') .setCustomId('play'), new MessageButton() @@ -54,7 +54,7 @@ export default { .setLabel('Pause') .setCustomId('pause'), new MessageButton() - .setStyle('DANGER') + .setStyle('SECONDARY') .setLabel('Skip') .setCustomId('skip'), new MessageButton() @@ -86,35 +86,35 @@ export default { collector.on('collect', async ctlButton => { if (ctlButton.customId === 'join') { await ctlButton.reply({content:'Joining voice channel', ephemeral:true}) - await voiceInit(bot); + return await voiceInit(bot); } if (ctlButton.customId === 'play') { await ctlButton.reply({content:'Resuming music', ephemeral:true}) - player.unpause(); + return player.unpause(); } if (ctlButton.customId === 'pause') { await ctlButton.reply({content:'Pausing music', ephemeral:true}) - player.pause(); + return player.pause(); } if (ctlButton.customId === 'skip') { await ctlButton.reply({content:`Skipping \`${audio}\`...`, ephemeral:true}) - player.pause(); - await searchAudio(bot); + player.stop(); + return await searchAudio(bot); } if (ctlButton.customId === 'next') { - await interaction.editReply({ components: [controlButtons2] }); + return await interaction.editReply({ components: [controlButtons2] }); } if (ctlButton.customId === 'back') { - await interaction.editReply({ components: [controlButtons] }); + return await interaction.editReply({ components: [controlButtons] }); } if (ctlButton.customId === 'leave') { await ctlButton.reply({content:'Leaving voice channel.', ephemeral:true}) console.log('Leaving voice channel...'); - destroyAudio(interaction); + return destroyAudio(interaction); } if (ctlButton.customId === 'stop') { await ctlButton.reply({content:'Powering off...', ephemeral:true}) - await stopBot(bot, interaction); + return await stopBot(bot, interaction); } }); diff --git a/commands/help.js b/commands/help.js index e23b105..291f5fe 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * diff --git a/commands/join.js b/commands/join.js index 72aae2e..0de2f14 100644 --- a/commands/join.js +++ b/commands/join.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * diff --git a/commands/list.js b/commands/list.js index 673b779..2b81acb 100644 --- a/commands/list.js +++ b/commands/list.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * diff --git a/commands/ping.js b/commands/ping.js index 14071ac..fc25135 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * diff --git a/commands/play.js b/commands/play.js index df5be96..f53ac21 100644 --- a/commands/play.js +++ b/commands/play.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * @@ -32,7 +32,7 @@ export default { .addIntegerOption(option => option.setName('int') .setDescription('Input a number for the selection for the audio file.') - .setRequired(true), + .setRequired(false), ), async execute(interaction, bot) { if (![config.botOwner].includes(interaction.user.id)) return await interaction.reply({ content: "You do not have permissions to execute this command.", ephemeral: true }); diff --git a/commands/stop.js b/commands/stop.js index c753a1b..ced8fe5 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local MP3 audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * diff --git a/music/README.md b/music/README.md deleted file mode 100644 index 57d8bda..0000000 --- a/music/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Put your music here -Any mp3 file should go here. \ No newline at end of file diff --git a/package.json b/package.json index 65e11d1..caa5209 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dlmp3", - "version": "1.0.0", + "version": "1.2.0", "type": "module", "main": "bot.js", "license": "GPL-3.0",