I'm working on a discord bot and need to check if a user is in my database or not so that I can make a profile for new users. I'm new at using async functions so I've been looking around for examples but can't seem to get it to work how I want.
Using Typescript / DiscordJS / mongoDB
let profileData;
try {
const makeProfile = async () => {
profileData = await profileModels.findOne({ userID: message.author.id });
if (!profileData) {
setTimeout(async () => {
await new profileSchema({
userID: message.author.id,
serverID: message.guild?.id,
balance: 0,
inventory: [],
bank: 0,
}).save();
}, 1000);
}
};
} catch (err) {
console.log(err);
}