Add err message when api key missing
This commit is contained in:
parent
6bfcb3b9f9
commit
b613ab8866
2 changed files with 15 additions and 11 deletions
|
@ -74,7 +74,7 @@ class Player {
|
||||||
this.queues = this.queues.filter((g) => g.guildID !== voiceChannel.id);
|
this.queues = this.queues.filter((g) => g.guildID !== voiceChannel.id);
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
// Searches the song
|
// 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');
|
if(!video) reject('Song not found');
|
||||||
// Joins the voice channel
|
// Joins the voice channel
|
||||||
let connection = await voiceChannel.join();
|
let connection = await voiceChannel.join();
|
||||||
|
|
24
src/Util.js
24
src/Util.js
|
@ -17,17 +17,21 @@ class Util {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
search = search.replace(/<(.+)>/g, "$1");
|
search = search.replace(/<(.+)>/g, "$1");
|
||||||
// Try with URL
|
// Try with URL
|
||||||
let video = await SYA.getVideo(search).catch(() => {});
|
SYA.getVideo(search).then(async (video) => {
|
||||||
if(video){
|
video = await video.fetch();
|
||||||
video = await video.fetch()
|
|
||||||
resolve(video);
|
resolve(video);
|
||||||
}
|
}).catch(async (err) => {
|
||||||
// Try with song name
|
if(err.message === "Bad Request"){
|
||||||
let results = await SYA.searchVideos(search, 1);
|
reject('Invalid Youtube Data v3 API key.');
|
||||||
if(results.length < 1) reject('Not found');
|
} else {
|
||||||
let fetched = await results.shift().fetch();
|
// Try with song name
|
||||||
results.push(fetched)
|
let results = await SYA.searchVideos(search, 1);
|
||||||
resolve(results.pop());
|
if(results.length < 1) return reject('Not found');
|
||||||
|
let fetched = await results.shift().fetch();
|
||||||
|
results.push(fetched);
|
||||||
|
resolve(results.pop());
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue