Skip to content

Commit

Permalink
fix(search): avoid APIError when search query didn't lead to any resu…
Browse files Browse the repository at this point in the history
…lts (#1442)

fix #1441
  • Loading branch information
Mirasaki authored Aug 10, 2023
1 parent f8340ab commit c2369ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions commands/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ export default {
results = await youtube.search(search, { limit: 10, type: "video" });
} catch (error: any) {
console.error(error);

interaction.editReply({ content: i18n.__("common.errorCommand") }).catch(console.error);
return;
}

if (!results) return;
if (!results || !results[0]) {
interaction.editReply({ content: i18n.__("search.noResults") })
return;
}

const options = results!.map((video) => {
return {
Expand Down
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"errorNotChannel": "You need to join a voice channel first!",
"resultEmbedTitle": "**Reply with the song number you want to play**",
"resultEmbedDesc": "Results for: {search}",
"optionQuery": "Search query"
"optionQuery": "Search query",
"noResults": "No results for query, please try something else"
},
"shuffle": {
"description": "Shuffle queue",
Expand Down

0 comments on commit c2369ab

Please sign in to comment.