From 65c6e002fc1e9c9812bf6dadf76e0ab2f7aa3a13 Mon Sep 17 00:00:00 2001 From: "lucas.mathieu" Date: Sat, 19 Dec 2020 12:27:48 +0100 Subject: [PATCH] Added random play --- index.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index af5da0c..401a456 100644 --- a/index.js +++ b/index.js @@ -32,13 +32,23 @@ client.on('message', message => { } else if (command === "play") { - Genius.search_song(args.join(" "), (err, song) => { - if (err) { - message.channel.send("Je connais pas \"" + args.join(" ") + "\"."); - } else { - play(message, song.id); - } - }); + if (args.length == 0) { + getList(message.author.id, songs => { + if (songs === undefined) { + message.channel.send("Vous devez ajouter des musiques à votre liste pour jouer aléatoirement."); + } else { + play(message, songs[Math.floor(Math.random() * songs.length)].id); + } + }) + } else { + Genius.search_song(args.join(" "), (err, song) => { + if (err) { + message.channel.send("Je connais pas \"" + args.join(" ") + "\"."); + } else { + play(message, song.id); + } + }); + } } else if (command === "add") {