error delete data mongodb

i would like that when the bot leaves a server it deletes all the information of the server in question. But it doesn't delete anything, can someone help me? Database: MongoDB
14 Replies
cheraph
cheraph16mo ago
No description
cheraph
cheraph16mo ago
error:
No description
probablyraging
probablyraging16mo ago
.findOne() is an asynchronous function that returns a promise, you need to await the promise before you can call .delete() on dataGuildDelete
cheraph
cheraph16mo ago
how can i do it then?
probablyraging
probablyraging16mo ago
await .fineOne()
cheraph
cheraph16mo ago
await no work
probablyraging
probablyraging16mo ago
Show code
cheraph
cheraph16mo ago
wait
cheraph
cheraph16mo ago
@ProbablyRaging
No description
cheraph
cheraph16mo ago
I can't await
probablyraging
probablyraging16mo ago
client.on() callback needs to be asyncronous Send the actual code, not just a screenshot, I'll show you the changes
cheraph
cheraph16mo ago
probablyraging
probablyraging16mo ago
client.on('guildDelete', async (guild) => {
//...
const guildDataToDelete = await schema.findOne({ guildId: guild.id });
if (guildDataToDelete) {
await guildDataToDelete.delete();
}
});
client.on('guildDelete', async (guild) => {
//...
const guildDataToDelete = await schema.findOne({ guildId: guild.id });
if (guildDataToDelete) {
await guildDataToDelete.delete();
}
});
Should work with the necessary changes
cheraph
cheraph16mo ago
ohh ok good THANKS