Cannot read property 'fetchBans' of undefined

随声附和 提交于 2021-01-29 10:10:36

问题


I'm trying out a new command, which is the unban command. However, if I run the code below I keep getting Cannot read property 'fetchBans' of undefined. I'm currently using v12.16.3.

  if(!message.member.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("You dont have permission to perform this command!")


    if(isNaN(args[0])) return message.channel.send("You need to provide an ID.")
    let bannedMember = await client.guild.fetchBans(args[0])
        if(!bannedMember) return message.channel.send("Please provide a user id to unban someone!")

    let reason = args.slice(1).join(" ")
        if(!reason) reason = "No reason given!"

    if(!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("I dont have permission to perform this command!")|
    message.delete()
    try {
        message.guild.guild.fetchBans(bannedMember, reason)
        message.channel.send(`${bannedMember.tag} has been unbanned from the guild!`)
    } catch(e) {
        console.log(e.message)
    }

    let embed = new Discord.MessageEmbed()
       .setColor('RANDOM')
       .setAuthor(`${message.guild.name} Modlogs`, message.guild.iconURL)
       .addField("Moderation:", "unban")
       .addField("Moderated on:", `${bannedMember.username} (${bannedMember.id})`)
       .addField("Moderator:", message.author.username)
       .addField("Reason:", reason)

        let sChannel = message.guild.channels.find(c => c.name === "modlog")
        sChannel.send(embed)

回答1:


message.guild.guild does not exist, remove the second guild:

message.guild.fetchBans(bannedMember, reason)


来源:https://stackoverflow.com/questions/61809975/cannot-read-property-fetchbans-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!