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