Cannot read properties of undefined (reading ‘fetchBans’)

Im trying to make a command with in my Discord bot to make unban a person. When I finnished the code I got an error. The error is Cannot read properties of undefined (reading ‘fetchBans’). The code I use to make it is

message.guild.cache.fetchBans().then(async bans => {
            if (bans.size === 0) return"No one is banned on the server!")
            let bannedUser = bans.find(ban => == userID)
            if (!bannedUser) return"This user isn't banned!")
            await message.guild.members.unban(bannedUser.user, reason).catch(err => {
                return"Something went wrong!")
            }).then(() => {
                let embed = new MessageEmbed()
                    .setTitle(`Member unbanned!`)

            embed.addField(`member = ${target.username}`, `reason = ${reason}`, false)

  {embeds: });

            if (row[0].logs_channel != null) this.client.channels.cache.get(row[0].logs_channel).send({embeds: })


The line where it goes wrong is this line:

 message.guild.cache.fetchBans().then(async bans => {

When I run this command it will give the error. I also tried to do something else. The code i tried else for that line is:

message.guild.fetchBans().then(async bans => {

This line also gave an error that says: TypeError: message.guild.fetchBans is not a function.

I don’t know what i can do about this. I hope somebody can help me.

Node.js version: 16.9.1 discord.js version: 13.1.0


According to the documentation there is no fetchBans on Guild. Maybe you’re looking for message.guild.bans.fetch().

It’s also worth noting that message.guild is nullable – if the message was a direct message (not sent in a guild) it will be null.