From b6fa324b703c1361848ac0a8394f5406af56b2c6 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Sat, 22 Feb 2020 11:19:00 +0100 Subject: [PATCH] fix: update typeconditions and catch errors --- src/Player.js | 2 +- src/Util.js | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Player.js b/src/Player.js index df432ba..372e13a 100644 --- a/src/Player.js +++ b/src/Player.js @@ -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); diff --git a/src/Util.js b/src/Util.js index db8fc5f..683c198 100644 --- a/src/Util.js +++ b/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); + } + } } }); });