Embed title of video
This commit is contained in:
parent
46b937a107
commit
e8486e9324
|
@ -2,6 +2,7 @@ const { addToQueue, playNextInQueue } = require('../utils/queueManager');
|
||||||
const ytDlpExec = require('yt-dlp-exec');
|
const ytDlpExec = require('yt-dlp-exec');
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'play',
|
name: 'play',
|
||||||
|
@ -18,37 +19,45 @@ module.exports = {
|
||||||
return message.reply('Please provide a YouTube link or a song name.');
|
return message.reply('Please provide a YouTube link or a song name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
let url;
|
let url, title;
|
||||||
if (isValidURL(searchQuery)) {
|
try {
|
||||||
url = searchQuery;
|
if (isValidURL(searchQuery)) {
|
||||||
} else {
|
url = searchQuery;
|
||||||
try {
|
const info = await ytDlpExec(url, { dumpSingleJson: true });
|
||||||
|
title = info.title;
|
||||||
|
} else {
|
||||||
const searchResult = await ytDlpExec(`ytsearch:${searchQuery}`, {
|
const searchResult = await ytDlpExec(`ytsearch:${searchQuery}`, {
|
||||||
dumpSingleJson: true,
|
dumpSingleJson: true,
|
||||||
noPlaylist: true,
|
noPlaylist: true,
|
||||||
format: 'bestaudio/best',
|
format: 'bestaudio/best',
|
||||||
quiet: true,
|
quiet: true,
|
||||||
});
|
});
|
||||||
url = searchResult.webpage_url;
|
url = searchResult.entries[0].webpage_url;
|
||||||
} catch (error) {
|
title = searchResult.entries[0].title;
|
||||||
console.error('yt-dlp search error:', error);
|
|
||||||
return message.reply('Could not find the song. Please try again.');
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
|
const embed = new EmbedBuilder()
|
||||||
try {
|
.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, {
|
await ytDlpExec(url, {
|
||||||
cookies: path.join(__dirname, '../cookies.txt'),
|
cookies: path.join(__dirname, '../cookies.txt'),
|
||||||
format: 'bestaudio',
|
format: 'bestaudio',
|
||||||
output: tempFilePath,
|
output: tempFilePath,
|
||||||
quiet: true,
|
quiet: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
addToQueue(message.guild.id, tempFilePath);
|
addToQueue(message.guild.id, tempFilePath);
|
||||||
playNextInQueue(message.guild.id, voiceChannel);
|
playNextInQueue(message.guild.id, voiceChannel);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('yt-dlp error:', 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.');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue