Acomoda mi código: const fs = require(`fs`);
const { EmbedBuilder } = require(`discord.js`);

// Función para actualizar la experiencia y el nivel del jugador
async function updateExp(playerRef, exp) {
  const playerDoc = await playerRef.get();
  const playerData = playerDoc.data();
  let playerLevel = playerData.level;
  let playerXp = playerData.xp + exp;
  let playerBaseXp = playerData.baseXp;
  let levelsGained = 0;
  
  while (playerXp >= playerBaseXp) {
    playerXp -= playerBaseXp;
    playerBaseXp = Math.round(playerBaseXp * 1.150);
    playerLevel += 1;
    levelsGained += 1;
  }
    
  await playerRef.update({ xp: playerXp, level: playerLevel, baseXp: playerBaseXp });
  return levelsGained;
}

module.exports = {
  name: `find`,
  description: `find a creature and kill it`,

  async execute(message, args, db) {
    const creaturesFile = `./utils/creatures.json`;

    const rawdata = fs.readFileSync(creaturesFile);
    const creatures = JSON.parse(rawdata);
    const userId = message.author.id;
    const playerRef = db.collection(`users`).doc(userId);

    const playerDoc = await playerRef.get();
    const playerData = playerDoc.data();
    
    const playerAttack = playerData.attack;
    const playerDefense = playerData.defense;
    const playerHp = playerData.hp;

    // Seleccionar criatura de acuerdo al nivel del usuario
    const filterCreatures = creatures.filter((creatures) => {
      return creatures.level == playerData.land;
    });

    const selectedCreature = filterCreatures[Math.floor(Math.random() * filterCreatures.length)];
    // Calcular daño del jugador y de la criatura
    const playerDamage = playerAttack + playerDefense;
    const creatureDamage = selectedCreature.attack + selectedCreature.defense;    
    let totalDamage = creatureDamage - playerDamage;
    if (totalDamage <= 0) {
      totalDamage = 0;
    }

    // Actualizar HP del jugador
    const tmpHp = playerHp - totalDamage;
    await playerRef.update({ hp: tmpHp });

    // Ganar XP y niveles después de vencer a la criatura
    const baseExp = selectedCreature.xp.base;
    const bonusExp = Math.floor(Math.random() * selectedCreature.xp.bonus);
    const totalExp = baseExp + bonusExp;
    try {
      const levels = await updateExp(playerRef, totalExp);

      // basic credit system//
      const baseCredit = selectedCreature.credit.base;
const bonusCredit = Math.floor(Math.random() * selectedCreature.credit.bonus);
const totalCredit = baseCredit + bonusCredit;
const playerCredit = playerData.credit + totalCredit;
await playerRef.update({ credit: playerCredit });

let itemFound = `Nothing`;
      
      const embed = new EmbedBuilder()
      .setColor("#5A199B")
      .setTitle(`Exploration Completed`)
      .setDescription(`You have found to **__${selectedCreature.name}__** and you ended up killing him.`)
      .setFields({name:`Log:`, value: `**XP**: ${totalExp}\n**HP**: ${tmpHp}\n**Credit**: ${totalCredit}`});


const item = selectedCreature.item;
const rate = Math.random();      
if(item && item.droprate && rate < item.droprate){
  const itemName = item.name;
  const playerInv = playerData.inventory || {};
  playerInv[itemName] = playerInv[itemName] ? playerInv[itemName] + 1 : 1;
  await playerRef.update({ inventory: playerInv }); 
  if(itemName){
   embed.setFields({name:`Log:`, value: `**XP**: ${totalExp}\n**HP**: ${tmpHp}\n**Credit**: ${totalCredit}\n**Item**: ${itemName}`});
  }
}

      return message.channel.send({embeds: [embed]});
      
    } catch (error) {
      console.error(error);
      return message.reply(`Ocurrió un error al actualizar la experiencia y el nivel del jugador.`);
    }
  }
}