From 37f18f6920bc2430d45e1e27821fb886086c6db6 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 8 Aug 2023 22:25:43 +0200 Subject: [PATCH] Prevents the bot to send empty data to discord --- src/commands/music/play.ts | 29 ++++++++++++++++------------- src/locales/fr.json | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index 1a9bc30..26da0e2 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -150,6 +150,7 @@ export default { }, autocomplete: async (interaction: AutocompleteInteraction) => { + const loc = getLocale(interaction.client, interaction.locale); const loc_default = interaction.client.locales.get(interaction.client.config.default_lang); const filename = getFilename(__filename); @@ -186,20 +187,22 @@ export default { return []; }); - // Slice the list if needed - if (tracks.length > 25) { - tracks = tracks.slice(0, 25); - } + // If tracks found + if (tracks.length > 0) { + // Slice the list if needed + if (tracks.length > 25) { + tracks = tracks.slice(0, 25); + } - // Returns a list of songs with their title and author - return interaction.respond( - tracks.map((t) => ({ - name: `${t.title} • ${t.author}`, - value: t.url, - })) - ); - } else { - return interaction.respond([]); + // Returns a list of songs with their title and author + return interaction.respond( + tracks.map((t) => ({ + name: `${t.title} • ${t.author}`, + value: t.url, + })) + ); + } } + return interaction.respond([{ name: loc.get("c_play9"), value: query }]); }, }; diff --git a/src/locales/fr.json b/src/locales/fr.json index fce91b8..b634f29 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -90,6 +90,7 @@ "c_play6": "Le bot ne joue rien en ce moment.", "c_play7": "Joue actuellement", "c_play8": "Demandé par", + "c_play9": "Aucun résultat trouvé", "c_stop_name": "stop", "c_stop_desc": "Stop la musique",