From 662223d2a9f9618f6fefcaaeac8cd4b7dcabcd64 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Fri, 7 Jul 2023 18:51:31 +0200 Subject: [PATCH] Add reply message if no results found --- commands/play.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/commands/play.js b/commands/play.js index e387ca8..439b9ff 100644 --- a/commands/play.js +++ b/commands/play.js @@ -30,6 +30,20 @@ module.exports = { const queue = useQueue(interaction.guild.id); const query = interaction.options.getString('query'); + const results = await player.search(query); + + if (!results || results.tracks.length === 0) { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**No track found**\nNo results found for \`${query}\`.` + ) + .setColor(embedColors.colorWarning) + ] + }); + } + try { const { track } = await player.play( interaction.member.voice.channel, @@ -61,7 +75,9 @@ module.exports = { ] }); } catch (e) { - console.log(`Error occured while trying to play track:\n\n${e}`); + console.log( + `Error: Error occured while trying to play track:\n\n${e}` + ); throw e; } }