我得到了一个 unban 命令代码,并在控制台中收到以下错误:
(节点:9348)UnhandledPromiseRejectionWarning:TypeError:无法在客户端读取 Object.execute(C:\Users\19nik\Documents\GitHub\bot-project\commands\unban.js:9:22)处未定义的属性“成员”。(C:\Users\19nik\Documents\GitHub\bot-project\gb.js:81:17) 在 Client.emit (events.js:315:20) 在 MessageCreateAction.handle (C:\Users\19nik\Documents \GitHub\bot-project\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) 在 Object.module.exports [as MESSAGE_CREATE] (C:\Users\19nik\Documents\GitHub\bot -project\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) 在 WebSocketManager.handlePacket (C:\Users\19nik\Documents\GitHub\bot-project\node_modules\discord.js \src\client\websocket\WebSocketManager.js:384:31) 在 WebSocketShard.onPacket (C:\Users\19nik\Documents\GitHub\bot-project\node_modules\discord.
这是我的代码:
const { MessageEmbed } = require('discord.js');
const fs = require("fs");
module.exports = {
name: `unban`,
description: `Unbans given user ID or mentioned user.`,
async execute(bot, args, message) {
if (!message.member.hasPermission(["BAN_MEMBERS"])) return message.channel.send("You do not have the required permissions to use the unban command.")
if (!args[0]) return message.channel.send("Provide me a valid USER ID.");
//This if() checks if we typed anything after "!unban"
let bannedMember;
//This try...catch solves the problem with the await
try {
bannedMember = await bot.users.cache.fetch(args[0])
} catch (e) {
if (!bannedMember) return message.channel.send("That's not a valid USER ID.")
}
//Check if the user is not banned
try {
await message.guild.fetchBan(args[0])
} catch (e) {
message.channel.send('This user is not banned.');
return;
}
let reason = args.slice(1).join(" ")
if (!reason) reason = "No reason provided."
if (!message.guild.me.hasPermission(["BAN_MEMBERS"])) return message.channel.send("I am missing permissions to unban.")
message.delete()
try {
message.guild.members.unban(bannedMember, { reason: reason })
message.channel.send(`${bannedMember.tag} has been unbanned.`)
console.log(`AUDIT LOG: [UNBAN] ${message.author.tag} unbanned ${member.user.tag} from ${message.guild.name}.`);
var readmessagefile = fs.readFileSync('./logging/UnbanLog.txt', 'utf-8');
var writemessagefile = fs.writeFileSync('./logging/UnbanLog.txt', 'Type: [UNBAN] ' + 'Time ' + '(' + message.createdAt + ')' + ' | ' + member.user.tag + ' from ' + message.guild.name + ' | Moderator ' + message.author.tag + '\n' + readmessagefile)
console.log('BOT LOG: [INTERNAL] Writing to unban log file.');
} catch (e) {
console.log(e.message)
}
}
}
我不知道该怎么办。它还弹出无法读取未定义的属性'hasPermissions'的错误。