From dfada15b007ed47bba6b1b27728ea30b24481049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 05:41:13 +0300 Subject: [PATCH] Updated next command --- src/client/commands/next.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/client/commands/next.js b/src/client/commands/next.js index da92e5a..a8a2e9d 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -6,8 +6,21 @@ module.exports = { async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id); - let station = client.stations[client.stations.findIndex(station => station.name == radio.station.name) + 1]; + let index = client.stations.findIndex(station => station.name == radio.station.name) + 1; + if(index == client.stations.length) index = 0; + + let station = client.stations[index]; + + if(!station) return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.noSearchResults, + ephemeral: true + }); + + interaction.deferUpdate(); + + let url = station.stream[station.stream.default]; + client.funcs.statisticsUpdate(client, interaction.guild, radio); radio.audioPlayer.stop(); @@ -15,9 +28,8 @@ module.exports = { radio.station = station; radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - client.funcs.play(interaction, interaction.guild, client, url); + client.funcs.play(null, interaction.guild, client, url); - return; } } } \ No newline at end of file