Extracted getList to a function

This commit is contained in:
2020-12-19 12:20:58 +01:00
parent d1ed48b3fe
commit 5f334e0ff7

View File

@@ -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"]);