我正在尝试为我的机器人创建一个取消禁止命令,但是每次我想测试命令 (!unban <userId>
) 时,我都没有得到预期的结果。相反,我收到了一个错误,如下所示。
这是我的代码:
const Discord = require('discord.js')
module.exports = {
name: 'unban',
usage: '%unban <userId> <reason>',
description: 'To unban someone',
async execute(client, message, args) {
if (!message.member.hasPermission("BAN_MEMBERS")) return;
if (!message.guild.me.hasPermission("BAN_MEMBERS")) return message.reply(`You do not have permission to unban`);
let userId = args[0];
if (!userId) return message.reply(`Please state a user ID to unban`);
let reason = args.slice(1).join(" ");
if (!reason) reason = "No reason mentioned";
if (userId === message.author.id) return message.reply(`You can not unban yourself`);
let bans = await message.guild.fetchBans();
if (bans.has(userId)) {
message.guild.members.unban(userId({ reason }))
message.channel.send(`Successfully unbanned **${userId}**`);
} else {
message.reply(`Provided ID is invalid or isn't a banned member`)
}
}
}
这是我得到的错误:
PS C:\Users\lolzy\OneDrive\Desktop\discordbot> node .
Cbs slave is online!
(node:23184) UnhandledPromiseRejectionWarning: TypeError: userId is not a function
at Object.execute (C:\Users\lolzy\OneDrive\Desktop\discordbot\commands\unban.js:19:41)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:23184) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of
an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:23184) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that
are not handled will terminate the Node.js process with a non-zero exit code.
答案 0 :(得分:0)
break
应该是 message.guild.members.unban(userId({ reason }))
,因为 userId 不是函数。