I've encountered a problem while setting up mongoose.
Here is my code:
const { SlashCommandBuilder } = require('@discordjs/builders');
const testSchema = require(`../../Schemas.js/test`);
module.exports = {
data: new SlashCommandBuilder()
.setName('dbtest')
.setDescription('db test'),
async execute(interaction) {
testSchema.findOne({ GuildID: interaction.guild.id, UserID: interaction.user.id}, async(err, data) => {
if (err) throw err;
if (!data) {
testSchema.create({
GuildID: interaction.guild.id,
UserID: interaction.user.id
})
}
if (data) {
console.log(data)
}
})
}
}
My error:
/Users/akimfly/akim-slash-bot/node_modules/mongoose/lib/model.js:2131
throw new MongooseError('Model.findOne() no longer accepts a callback');
^
MongooseError: Model.findOne() no longer accepts a callback
at Function.findOne (/Users/akimfly/akim-slash-bot/node_modules/mongoose/lib/model.js:2131:11)
at Object.execute (/Users/akimfly/akim-slash-bot/src/commands/Community/databasetest.js:10:20)
at Object.execute (/Users/akimfly/akim-slash-bot/src/events/interactionCreate.js:12:21)
at Client.<anonymous> (/Users/akimfly/akim-slash-bot/src/functions/handleEvents.js:8:58)
at Client.emit (node:events:513:28)
at InteractionCreateAction.handle (/Users/akimfly/akim-slash-bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/Users/akimfly/akim-slash-bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/Users/akimfly/akim-slash-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31)
at WebSocketShard.onPacket (/Users/akimfly/akim-slash-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:489:22)
at WebSocketShard.onMessage (/Users/akimfly/akim-slash-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:328:10)