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) {
|
play(voiceChannel, songName) {
|
||||||
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) => {
|
||||||
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);
|
if(typeof songName !== "string") return reject("songName must be type of string. value="+songName);
|
||||||
// Searches the song
|
// Searches the song
|
||||||
let video = await Util.getFirstYoutubeResult(songName, this.SYA);
|
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"){
|
if(err.message === "Bad Request"){
|
||||||
reject('Invalid Youtube Data v3 API key.');
|
reject('Invalid Youtube Data v3 API key.');
|
||||||
} else {
|
} else {
|
||||||
// Try with song name
|
try {
|
||||||
let results = await SYA.searchVideos(search, 1);
|
// Try with song name
|
||||||
if(results.length < 1) return reject('Not found');
|
let results = await SYA.searchVideos(search, 1);
|
||||||
let fetched = await results.shift().fetch();
|
if(results.length < 1) return reject('Not found');
|
||||||
results.push(fetched);
|
let fetched = await results.shift().fetch();
|
||||||
resolve(results.pop());
|
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