Only support mp3 wav mp4 webm

This commit is contained in:
loicbersier 2019-01-16 00:29:10 +01:00
parent b64bab354f
commit 0a1474887d

View file

@ -31,13 +31,19 @@ class musicCommand extends Command {
async exec(message,args) {
let link;
let Attachment = (message.attachments).array();
if (!args.music && Attachment[0]) {
if (!Attachment[0].url.endsWith('mp3' || 'wav' || 'mp4' || 'webm'))
return message.channel.send('Only mp3,wav,mp4 and webm are supported');
link = Attachment[0].url;
} else {
link = args.music;
if (!link.endsWith('mp3' || 'wav' || 'mp4' || 'webm'))
return message.channel.send('Only mp3,wav,mp4 and webm are supported');
}
let video = youtubedl(link, ['-x', '--audio-format', 'mp3']);
video.pipe(fs.createWriteStream('./music.mp3'));
video.on('error', function error(err) {
@ -53,12 +59,17 @@ class musicCommand extends Command {
if (!response.results[0])
return message.channel.send('Could not identify the music');
let time = response.results[0].recordings[0].duration;
let minutes = Math.floor(time / 60);
let seconds = time - minutes * 60;
const musicEmbed = new MessageEmbed()
.setColor('#ff9900')
.setTitle('Music found!')
.addField('Title', response.results[0].recordings[0].title, true)
.addField('Artist', response.results[0].recordings[0].artists[0].name, true)
.addField('Album', response.results[0].recordings[0].releasegroups[0].title, true);
.addField('Album', response.results[0].recordings[0].releasegroups[0].title, true)
.addField('Duration', `${minutes}:${seconds}`);
message.channel.send(musicEmbed);