每次我尝试使用bot更改服务器中其他人的昵称时(甚至是我自己在朋友服务器中),都会失败,并出现以下错误:
(node:11620) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (C:\Users\(User)\Desktop\Discord Bot\Nick-Cycle\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:11620) 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:11620) [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.
我检查了一下,它确实具有“管理昵称”,并且它的角色就在所有者的下面。我要更改昵称的人,他的最高职责远远低于机器人的职责。
Image of Bot's role, position, and Manage Nickname's permission.
这是代码:
client.on('message', async message => {
const prefix = ";"
if (message.author.bot) return;
if (!message.guild) return;
if (!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
switch(cmd) {
case "setnick":
if (!message.guild.me.hasPermission("MANAGE_NICKNAMES")) return message.channel.send("I don't have Manage Nicknames!");
if (!args[0]) return message.channel.send("Not enough arguments!");
if (args[0] === getUserFromMention(args[0])) {
const user = getUserFromMention(args[0])
if (!args[1]) return message.channel.send("Not enough arguments!");
message.guild.members.fetch(user).setNickname(args[1]);
}
else {
message.member.setNickname(args[0]);
}
break;
}
});
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
return client.users.cache.get(mention);
}
}
怎么了?有故障吗?角色有问题吗?还是我的代码有问题?