I'm trying to check if a player is already in my database and if not send him a custom discord message.
I have an async function that awaits the response of my database (I am using supabase). If the user does not exist it returns false, else it returns true.
async function doesUserExist(user_id:string){
let id = await database.GetUserInfo(user_id)
if (id == null){
return false;
}
return true;
}
This info is checked when a message is send to the bot. In the code snippet below I use the response of the async function to determine if I should send a discord message. However the code snippet never runs even when the output of the function should be true.
client.on("messageCreate", (message) => {
if(!doesUserExist(message.author.id)) {
// do something
}
}
I presume this has something to do with async functions returning promise and therefore the if statement just never fires. I am however fairly new to typescript (and javascript).
the packages I am using are
If you have any further questions regarding my issue feel free to ask them.
async (message) => {and you should resolve the promise first, i.eif(! await doesUserExist(message.author.id)) {client.onis a function. It doesn't care if it's a synchronous function (the default) or an asynchronous function (specified by theasynckeyword).