This commit is contained in:
Wizzard 2024-08-17 17:05:26 -04:00
parent db60021e08
commit 81c53cb304
1 changed files with 17 additions and 2 deletions

View File

@ -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;
}
}
}