I have developed a unique adventure command that searches for a player's profile in a Mongo database to calculate various game metrics such as xp and coins. While my other database commands are working flawlessly, this particular command is causing an issue. It correctly identifies the correct document initially, but when populating the command with information from the retrieved document, it always pulls data from the first document in the database which matches my profile. So, whenever someone initiates the adventure command, it calculates everything based on my profile information and then adds it to the correct user's profile. Consequently, players keep earning xp and coins based on my profile data, not their own. The code snippet is provided below for your reference.
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Collection, MessageActionRow, MessageButton } = require("discord.js");
const econModel = require('../models/econModel');
const humanizeDuration = require('humanize-duration');
const adventureCooldowns = new Collection();
module.exports = {
data: new SlashCommandBuilder()
.setName("adventure")
.setDescription("Explore the world and find treasure"),
execute(interaction){
// Implementation details here
}
}
As evident, the issue arises when trying to access the data from the called document through Account.Exp, which consistently picks up details from the initial database document. I have been struggling for a week to resolve this problem but have not made any significant progress. Any insights on how to prevent this issue?