Embed title of video

This commit is contained in:
Wizzard 2024-08-17 11:57:00 -04:00
parent 46b937a107
commit e8486e9324
1 changed files with 22 additions and 13 deletions

View File

@ -2,6 +2,7 @@ const { addToQueue, playNextInQueue } = require('../utils/queueManager');
const ytDlpExec = require('yt-dlp-exec');
const { v4: uuidv4 } = require('uuid');
const path = require('path');
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: 'play',
@ -18,37 +19,45 @@ module.exports = {
return message.reply('Please provide a YouTube link or a song name.');
}
let url;
if (isValidURL(searchQuery)) {
url = searchQuery;
} else {
try {
let url, title;
try {
if (isValidURL(searchQuery)) {
url = searchQuery;
const info = await ytDlpExec(url, { dumpSingleJson: true });
title = info.title;
} else {
const searchResult = await ytDlpExec(`ytsearch:${searchQuery}`, {
dumpSingleJson: true,
noPlaylist: true,
format: 'bestaudio/best',
quiet: true,
});
url = searchResult.webpage_url;
} catch (error) {
console.error('yt-dlp search error:', error);
return message.reply('Could not find the song. Please try again.');
url = searchResult.entries[0].webpage_url;
title = searchResult.entries[0].title;
}
}
const tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
try {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Now Playing')
.setDescription(`**${title}**`)
.setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() });
message.channel.send({ embeds: [embed] });
const tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
await ytDlpExec(url, {
cookies: path.join(__dirname, '../cookies.txt'),
format: 'bestaudio',
output: tempFilePath,
quiet: true,
});
addToQueue(message.guild.id, tempFilePath);
playNextInQueue(message.guild.id, voiceChannel);
} catch (error) {
console.error('yt-dlp error:', error);
message.reply('Failed to download video with yt-dlp.');
message.reply('Failed to retrieve or download video. Please try again.');
}
},
};