diff options
| -rw-r--r-- | AudioBackend.js | 15 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | bot.js | 21 | ||||
| -rw-r--r-- | commands/list.js | 8 | ||||
| -rw-r--r-- | package.json | 12 |
5 files changed, 24 insertions, 34 deletions
diff --git a/AudioBackend.js b/AudioBackend.js index d7b6852..53acc61 100644 --- a/AudioBackend.js +++ b/AudioBackend.js @@ -28,11 +28,11 @@ import { } from '@discordjs/voice' import { MessageEmbed } from 'discord.js' import config from './config.json' assert {type: 'json'} -import fs from 'fs' +import { readdirSync, writeFile } from 'node:fs' export const player = createAudioPlayer(); export let audio; -export let files = fs.readdirSync('music'); +export let files = readdirSync('music'); let fileData; export async function voiceInit(bot) { @@ -52,13 +52,13 @@ export async function voiceInit(bot) { }); player.on('idle', () => { - console.log("Music has finished playing, shuffling the beats...") + console.log("Beat has finished playing, shuffling the beats...") searchAudio(bot); }) await searchAudio(bot); return connection.subscribe(player); - }).catch(e => { console.error("The voice channel does not exist!\\n(Have you looked at your configuration?)") }) + }).catch(e => { console.error(e) }) } export async function searchAudio(bot){ @@ -78,12 +78,13 @@ export async function playAudio(bot) { await player.play(resource); - audio = audio.split('.').slice(0, -1).join('.'); console.log('Now playing: ' + audio); + audio = audio.split('.').slice(0, -1).join('.'); + if (config.txtFile === true) { fileData = "Now Playing: " + audio; - fs.writeFile("./now-playing.txt", fileData, (err) => { + writeFile("./now-playing.txt", fileData, (err) => { if (err) console.log(err); }); @@ -102,7 +103,7 @@ export async function playAudio(bot) { export function destroyAudio(interaction) { if (config.txtFile === true) { fileData = "Now Playing: Nothing"; - fs.writeFile("now-playing.txt", fileData, (err) => { + writeFile("now-playing.txt", fileData, (err) => { if (err) console.log(err); }); @@ -48,7 +48,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). +When forking the project, you can make your own version of DLAP or help contribute to the project (See the "Contributing" section). You need to edit `/commands/about.js` to uncomment the `.addField('Forked by', '[your name] (discord#0000)')` section. @@ -1,6 +1,6 @@ /************************************************************************** * - * DLMP3 Bot: A Discord bot that plays local audio tracks. + * DLAP Bot: A Discord bot that plays local audio tracks. * (C) Copyright 2022 * Programmed by Andrew Lee * @@ -20,22 +20,13 @@ ***************************************************************************/ import { Client, MessageEmbed, Collection, version } from 'discord.js' import { voiceInit } from './AudioBackend.js' -import fs from 'fs' +import { readdirSync } from 'node: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'; - -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); -} + +bot.login(config.token); + /** * Project Ideas: @@ -47,7 +38,7 @@ if (fs.existsSync(dir)) { // Slash Command Handler bot.commands = new Collection(); -const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); +const commandFiles = readdirSync('./commands').filter(file => file.endsWith('.js')); for (const file of commandFiles) { const { default: command } = await import(`./commands/${file}`); diff --git a/commands/list.js b/commands/list.js index 2b81acb..247e060 100644 --- a/commands/list.js +++ b/commands/list.js @@ -20,7 +20,7 @@ ***************************************************************************/ import { SlashCommandBuilder } from '@discordjs/builders' -import fs from 'fs' +import { readdirSync } from 'fs' const musicFolder = './music'; @@ -29,9 +29,7 @@ export default { .setName('list') .setDescription('Lists the available audio tracks'), async execute(interaction) { - await interaction.reply('Listing the available audio tracks...'); - fs.readdirSync(musicFolder).forEach(file => { - console.log(file); - }); + const beats = readdirSync(musicFolder).join('\n'); + await interaction.reply(`Listing the available audio tracks...\`\`\`${beats}\`\`\``); }, };
\ No newline at end of file diff --git a/package.json b/package.json index caa5209..9a07e1f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "dlmp3", + "name": "dlap", "version": "1.2.0", "type": "module", "main": "bot.js", @@ -9,15 +9,15 @@ }, "dependencies": { "@discordjs/builders": "^0.12.0", - "@discordjs/opus": "^0.3.2", + "@discordjs/opus": "^0.7.0", "@discordjs/rest": "^0.3.0", - "@discordjs/voice": "^0.5.5", + "@discordjs/voice": "^0.8.0", "discord-api-types": "^0.30.0", "discord.js": "^13.6.0", - "ffmpeg-static": "^4.2.5", - "libsodium-wrappers": "^0.7.9" + "ffmpeg-static": "^5.0.0", + "libsodium-wrappers": "^0.7.10" }, "devDependencies": { - "nodemon": "^2.0.4" + "nodemon": "^2.0.15" } } |
