Added error if no result found

This commit is contained in:
2020-12-19 10:50:10 +01:00
parent e2201ded4a
commit 27632ff226
2 changed files with 57 additions and 53 deletions

View File

@@ -10,9 +10,9 @@ class Genius {
url: "https://api.genius.com/search?q=" + q,
headers: {'Authorization': 'Bearer ' + config["genius-token"]}
}).then(response => {
return callback(response.data.response.hits[0].result);
return callback(null, response.data.response.hits[0].result);
}).catch(err => {
console.error(err);
return callback(err);
})
}

View File

@@ -31,7 +31,10 @@ client.on('message', message => {
}
else if (command === "play") {
Genius.search_song(args.join(" "), song => {
Genius.search_song(args.join(" "), (err, song) => {
if (err) {
message.channel.send("No result found for \"" + args.join(" ") + "\".");
} else {
Genius.get_lyrics(song.id, true, (err, lyrics) => {
if (err) {
console.log("Error while fetching lyrics: " + err.message);
@@ -84,6 +87,7 @@ client.on('message', message => {
});
}
});
}
});
}
});