问题
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