Add err message when api key missing

This commit is contained in:
Androz2091 2020-01-12 17:13:57 +01:00
parent 6bfcb3b9f9
commit b613ab8866
2 changed files with 15 additions and 11 deletions

View file

@ -74,7 +74,7 @@ class Player {
this.queues = this.queues.filter((g) => g.guildID !== voiceChannel.id);
return new Promise(async (resolve, reject) => {
// Searches the song
let video = await Util.getFirstYoutubeResult(songName, this.SYA).catch(() => {});
let video = await Util.getFirstYoutubeResult(songName, this.SYA);
if(!video) reject('Song not found');
// Joins the voice channel
let connection = await voiceChannel.join();

View file

@ -17,17 +17,21 @@ class Util {
return new Promise(async (resolve, reject) => {
search = search.replace(/<(.+)>/g, "$1");
// Try with URL
let video = await SYA.getVideo(search).catch(() => {});
if(video){
video = await video.fetch()
SYA.getVideo(search).then(async (video) => {
video = await video.fetch();
resolve(video);
}
// Try with song name
let results = await SYA.searchVideos(search, 1);
if(results.length < 1) reject('Not found');
let fetched = await results.shift().fetch();
results.push(fetched)
resolve(results.pop());
}).catch(async (err) => {
if(err.message === "Bad Request"){
reject('Invalid Youtube Data v3 API key.');
} else {
// Try with song name
let results = await SYA.searchVideos(search, 1);
if(results.length < 1) return reject('Not found');
let fetched = await results.shift().fetch();
results.push(fetched);
resolve(results.pop());
}
});
});
}