TheJulianJara
TheJulianJara

Reputation: 1

Cannot read properties of undefined (reading 'guilds') on discord.js v13

I have this problem and I don't know how to solve it, I'm new to this, so if you can help me it would be the best :D

Error:

    let Servers = client.guilds.cache.filter(g => g)
                         ^

TypeError: Cannot read properties of undefined (reading 'guilds')

And this would be the code snippet where the error is found.

async function checkUnbans() {
    let Servers = client.guilds.cache.filter(g => g)
    Servers.map(async g => {
        let SDB = await ServerSettings.findOne({GuildID: g.id})
        if(!SDB) return CreateServer(g.id)
        let Channel = g.channels.cache.get(SDB.GuildConfig[0].ModLogs.Channel)
        if(Channel) {
            let FBanned = await ModLogs.find({GuildID: g.id})
            FBanned.forEach(async (u) => {
                if(u.Type == "TEMPBAN") {
                    let Time = u.Time || 0
                    if(parseInt(u.OcurredDate) + parseInt(Time) < Date.now()) {
                        if(u.Unbanned == false) {
                        
                            let c = g.members.cache.get(u.UserID)
                            if(!c) {
                                let count = await ModLogs.countDocuments({GuildID: g.id})
                                 await UnbanM(g, u, count, Channel)
                            }
                        }
                    }
                }
            })
        }
    })
}

If this is any information, this is how I define some elements.

const ServerSettings = require('../models/ServerConfigModel')
const ModLogs = require('../models/ModLogs')
const { CreateServer } = require('./CreateDB')

Upvotes: 0

Views: 1384

Answers (1)

user18299570
user18299570

Reputation:

You need to define the serverL

let server= message.guild.server.cache.find(server=> server.name === 'bot-logs')

I hope this works!

Upvotes: 2

Related Questions