From 5f334e0ff77c8cb6c4d4b57c8f43660d8c3ba0db Mon Sep 17 00:00:00 2001 From: "lucas.mathieu" Date: Sat, 19 Dec 2020 12:20:58 +0100 Subject: [PATCH] Extracted getList to a function --- index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 702ef1f..af5da0c 100644 --- a/index.js +++ b/index.js @@ -67,10 +67,7 @@ client.on('message', message => { } else if (command === "list") { - fs.readFile('data.json', (err, data) => { - if (err) throw err; - data = JSON.parse(data); - const songs = data[message.author.id]; + getList(message.author.id, songs => { if (songs === undefined) { message.reply("Vous n'avez pas encore ajouté de musiques"); } else { @@ -140,4 +137,12 @@ function play(message, song_id) { }); } +async function getList(user_id, callback) { + fs.readFile('data.json', (err, data) => { + if (err) throw err; + data = JSON.parse(data); + callback(data[user_id]); + }); +} + client.login(config["discord-token"]); \ No newline at end of file