From 81c53cb304aecc36460604b13cb1483dc4d704d9 Mon Sep 17 00:00:00 2001 From: Wizzard Date: Sat, 17 Aug 2024 17:05:26 -0400 Subject: [PATCH] Logging --- commands/play.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/commands/play.js b/commands/play.js index 41366cd..37c21fd 100644 --- a/commands/play.js +++ b/commands/play.js @@ -3,7 +3,6 @@ const { v4: uuidv4 } = require('uuid'); const path = require('path'); const { EmbedBuilder } = require('discord.js'); const fs = require('fs'); - const { exec } = require('child_process'); module.exports = { @@ -14,7 +13,11 @@ module.exports = { const searchQuery = args.join(' '); const voiceChannel = message.member.voice.channel; + console.log(`Received command: play ${searchQuery}`); + console.log(`Voice channel: ${voiceChannel ? voiceChannel.name : 'None'}`); + if (!voiceChannel) { + console.error('User is not in a voice channel.'); return message.reply('You need to be in a voice channel to play music!'); } @@ -46,10 +49,12 @@ module.exports = { message.channel.send({ embeds: [embed] }); + console.log('Adding to queue and attempting to play.'); addToQueue(message.guild.id, tempFilePath, title, voiceChannel); playNextInQueue(message.guild.id); return; } else { + console.error('Attachment is not an MP3 file.'); return message.reply('Only MP3 files are supported for uploads.'); } } @@ -78,6 +83,7 @@ module.exports = { message.channel.send({ embeds: [embed] }); + console.log('Adding to queue and attempting to play.'); addToQueue(message.guild.id, tempFilePath, title, voiceChannel); playNextInQueue(message.guild.id); return; @@ -104,12 +110,14 @@ module.exports = { message.channel.send({ embeds: [embed] }); + console.log('Adding to queue and attempting to play.'); addToQueue(message.guild.id, tempFilePath, title, voiceChannel); playNextInQueue(message.guild.id); return; } else { tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`); + console.log(`YouTube link received: ${searchQuery}`); exec(`yt-dlp --cookies ${path.join(__dirname, '../cookies.txt')} --print title ${searchQuery}`, (error, stdout, stderr) => { if (error) { console.error(`Error getting title: ${error}`); @@ -127,6 +135,8 @@ module.exports = { return; } + console.log(`Downloaded and saved: ${tempFilePath}`); + const embed = new EmbedBuilder() .setColor('#0099ff') .setTitle('Now Playing') @@ -136,12 +146,14 @@ module.exports = { message.channel.send({ embeds: [embed] }); + console.log('Adding to queue and attempting to play.'); addToQueue(message.guild.id, tempFilePath, title, voiceChannel); playNextInQueue(message.guild.id); }); }); } } else { + console.log(`Performing YouTube search: ${searchQuery}`); exec(`yt-dlp --cookies ${path.join(__dirname, '../cookies.txt')} --dump-single-json "ytsearch:${searchQuery}"`, (error, stdout, stderr) => { if (error) { console.error(`Error searching: ${error}`); @@ -163,6 +175,8 @@ module.exports = { return; } + console.log(`Downloaded and saved: ${tempFilePath}`); + const embed = new EmbedBuilder() .setColor('#0099ff') .setTitle('Now Playing') @@ -172,6 +186,7 @@ module.exports = { message.channel.send({ embeds: [embed] }); + console.log('Adding to queue and attempting to play.'); addToQueue(message.guild.id, tempFilePath, title, voiceChannel); playNextInQueue(message.guild.id); }); @@ -192,4 +207,4 @@ function isValidURL(string) { } catch (_) { return false; } -} +} \ No newline at end of file