fix: update typeconditions and catch errors
This commit is contained in:
parent
094f1aa36c
commit
b6fa324b70
2 changed files with 15 additions and 7 deletions
|
@ -94,7 +94,7 @@ class Player {
|
|||
play(voiceChannel, songName) {
|
||||
this.queues = this.queues.filter((g) => g.guildID !== voiceChannel.id);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if(typeof voiceChannel !== VoiceChannel) return reject("voiceChannel must be type of VoiceChannel. value="+voiceChannel);
|
||||
if(!voiceChannel || typeof voiceChannel !== "object") return reject("voiceChannel must be type of VoiceChannel. value="+voiceChannel);
|
||||
if(typeof songName !== "string") return reject("songName must be type of string. value="+songName);
|
||||
// Searches the song
|
||||
let video = await Util.getFirstYoutubeResult(songName, this.SYA);
|
||||
|
|
20
src/Util.js
20
src/Util.js
|
@ -25,12 +25,20 @@ class Util {
|
|||
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());
|
||||
try {
|
||||
// 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());
|
||||
} catch(err){
|
||||
if(err.message === "Bad Request"){
|
||||
reject('Invalid Youtube Data v3 API key.');
|
||||
} else {
|
||||
reject(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue