if(m.content.toLowerCase() === "Yes" || "y") { async function fights() { const embed = new MessageEmbed() .setDescription("Your turn, What do you wanted to do?") .addField("Action List:", "Attack\nBlock\nDodge") .setColor('RANDOM') .setTimestamp() message.channel.send({embeds: [embed]}) const msg_filter =(m) => m.author.id === message.author.id; const collector = await message.channel.createMessageCollector({filter: msg_filter, max: 1, timer: 15000}) const exist = await economy.findOne({ guildID: message.guild.id, memberID: message.author.id }) let min_damage_player = exist.min_damage; let max_damage_player = exist.max_damage; let final_damage_player = Math.floor(Math.random() * (max_damage_player - min_damage_player) + min_damage_player); collector.on('collect', async(m) => { if(m.content.toLowerCase() === "attack" || "attk") { let percent = Math.floor(Math.random() * 100); if(percent > 20) { const new_health_enemy = enems.enemy_health - final_damage_player; const new_health_player = exist.health - cat_random_damage; const embed = new MessageEmbed() .setDescription(`You attacked the cat and dealth ${final_damage_player} damage!\nThen the cat attacked you and dealth ${cat_random_damage} damage!`) .addField("Your Status:", `Health: ${new_health_player}/${exist.max_health}`, true) .addField("Enemy Status:", `Health: ${new_health_enemy}/${enems.enemy_max_health}`, true) .setColor('RANDOM') .setTimestamp() message.channel.send({embeds: [embed]}) economy.findOneAndUpdate({ guildID: message.guild.id, memeberID: message.author.id }, {$inc: {health: new_health_player}}, async(err, data) => { if(data) { data.health = new_health_player; await data.save(); } }) enemy.findOneAndUpdate({ guildID: message.guild.id, userID: message.author.id }, {$inc: {$enemy_health: new_health_enemy}}, async(err, data) => { if(data) { data.enemy_health = new_health_enemy await data.save(); } }) } else { const new_health_player = exist.health - cat_random_damage; economy.findOneAndUpdate({ guildID: message.guild.id, memeberID: message.author.id }, {$inc: {$health: new_health_player}}, async(err, data) => { if(data) { data.health = new_health_player; await data.save(); } }) const embed = new MessageEmbed() .setDescription(`You attacked the cat but unfortunately the cat dodge your attack!\nThen the cat attacked you and dealth ${cat_random_damage} damage!`) .addField("Your Status:", `Health: ${exist.health}/${exist.max_health}`, true) .addField("Enemy Status:", `Health: ${enems.enemy_health}/${enems.enemy_max_health}`, true) .setColor('RANDOM') .setTimestamp() await message.channel.send({embeds: [embed]}) } } else if(m.content.toLowerCase() === "block") { //some code here for block command } else if(m.content.toLowerCase() === "dodge") { //some code here for dodge command } }) const enemy_health_bar = enems.enemy_health - final_damage_player; if (enemy_health_bar != 0) { //This is the start where I callback the function fights(enemy_health_bar); } else if(enems.enemy_health <= 0) { ended(); } } //End of callback fights(enems.enemy_health); function ended() { enemy.findOneAndDelete({ guildID: message.guild.id, userID: message.author.id }); let min_exp = 1; let max_exp = 15; let final_exp = Math.floor(Math.random() * (max_exp - min_exp) + min_exp) let min_cash = 1; let max_cash = 20; let final_cash = Math.floor(Math.random() * (max_cash - min_cash) + min_cash); economy.findOneAndUpdate({ guildID: message.guild.id, userID: message.author.id }, {$inc: {$exp: final_exp}}, {$inc: {$cash: final_cash}}, async(err, data) => { if(data) { data.exp += final_exp; data.cash += final_cash; data.save() const embed = new MessageEmbed() .setDescription("Congratulations! You won againts a cat, Here's your reward") .addFields( {name: "EXP:", value: `${final_exp}`, inline: true}, {name: "CASH:", value: `${final_cash}`, inline: true} ) .setColor('RANDOM') .setTimestamp() message.channel.send({embeds: [embed]}) } }) } } else if(m.content.toLowerCase() === "No" || m.content.toLowerCase() === "N") { console.log("false") }