I am trying to check if mongodb has a value to run an event, I have the code
if (guildSchema.events.channel.creates.enabled === false) {
And in the database the path is events -> channel -> creates -> enabled
but when creating a channel it returns the error TypeError: Cannot read properties of undefined (reading 'creates')
Code:
const guildSchema = require('../../models/guildSchema');
const data = await guildSchema.findOne({
id: channel.guild.id
});
if (!data) {
return;
}
if (data) {
if (guildSchema.events.channel.creates.enabled === false) {
// CODE
} else {
return;
}
}