I am currently working on developing a Discord bot and I need to implement a feature that checks if a user is already in the database in order to create a profile for new users. Since I am still fairly new to using async functions, I have been searching for examples but have not been able to achieve the desired functionality yet.
The technologies I am utilizing include Typescript, DiscordJS, and mongoDB.
let userProfileData;
try {
const createProfile = async () => {
userProfileData = await profileModels.findOne({ userID: message.author.id });
if (!userProfileData) {
setTimeout(async () => {
await new profileSchema({
userID: message.author.id,
serverID: message.guild?.id,
balance: 0,
inventory: [],
bank: 0,
}).save();
}, 1000);
}
};
} catch (error) {
console.log(error);
}