Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
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 message.channel.send("No one is banned on the server!")
            let bannedUser = bans.find(ban => ban.user.id == userID)
            if (!bannedUser) return message.channel.send("This user isn't banned!")
            await message.guild.members.unban(bannedUser.user, reason).catch(err => {
                return message.channel.send("Something went wrong!")
            }).then(() => {
                let embed = new MessageEmbed()
                    .setColor("GREEN")
                    .setTitle(`Member unbanned!`)
                    .setDescription("")
                    .setTimestamp()
                    .setFooter(this.client.user.username)

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


            message.channel.send({embeds: [embed]});

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

            message.delete()
        })

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

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda