Extracted getList to a function
This commit is contained in:
13
index.js
13
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"]);
|
||||
Reference in New Issue
Block a user