【发布时间】:2021-10-24 11:57:29
【问题描述】:
我制作 discord 机器人已经有一段时间了,最近我为它添加了一个 kick 功能,但是每当我对角色比机器人更高的人使用该命令时,机器人就会自动关闭。我正在使用不和谐 v12.22.1
这是我的代码
const { member, mentions } = message
const tag = `<@${member.id}>`
if (
member.hasPermission('KICK_MEMBERS')
) {
const target = mentions.users.first()
if (target) {
const targetMember = message.guild.members.cache.get(target.id)
targetMember.kick()
const embed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setDescription(`that user has been KICKED`);
message.channel.send(embed);
} else {
message.channel.send(`${tag} Please specify someone to kick.`)
}
} else {
message.channel.send(
`${tag} You do not have permission to use this command.`
)
}
})
})
它给了我这个错误:
(node:339) 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:339) [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.
【问题讨论】:
-
您收到任何错误吗?您使用的是 discord.js v12 还是 v13?我们需要更多细节。
-
是的,它给出了这个很长的错误,:s/discord.js/src/rest/RequestHandler.js:39:14) (node:339) UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。我也在使用不和谐 v12.22.1
-
能否将错误添加到问题中,以便读者真正阅读和理解错误?
-
好吧,我做到了,现在你知道我该如何解决这个问题了
标签: javascript node.js discord discord.js