无法读取未定义的属性“fetchBans"

时间:2023-02-10
本文介绍了无法读取未定义的属性“fetchBans"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一个新命令,即 unban 命令.但是,如果我运行下面的代码,我会不断收到 Cannot read property 'fetchBans' of undefined.我目前使用的是 v12.16.3.

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)

推荐答案

message.guild.guild不存在,删除第二个guild:

message.guild.fetchBans(bannedMember, reason)

这篇关于无法读取未定义的属性“fetchBans"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:如何让 selfbot 加入服务器? 下一篇:Discord.js:message.guild.channels.forEach 不是函数

相关文章

最新文章