簡體   English   中英

在 discord.js 中更改昵稱時缺少權限錯誤

[英]Missing Permissions error when changing nicknames in discord.js

每次我嘗試使用我的機器人更改服務器中其他人的昵稱(或者甚至是我自己在朋友服務器中的昵稱)時,它都會失敗,並出現以下錯誤:

(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.

我檢查了一下,它確實有管理昵稱,而且它的角色就在所有者之下。 我要更改昵稱的人,他的最高角色遠低於機器人。

Bot 角色的圖像,position,以及 Manage Nickname 的權限。

這是代碼:

 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); } }

怎么了? 這是一個小故障嗎? 角色有什么問題嗎? 還是我的代碼有問題?

好消息。 您的代碼不是問題所在。 問題是您的機器人角色如何定位以及它擁有什么權限。 確保機器人有能力更改其他人的名字,並且它的角色高於受害者的角色。 希望這可以幫助!

在此處輸入圖像描述

打開這個

在此處輸入圖像描述

我解決了。 事實證明它並沒有像它應該的那樣接受 arguments,而是一直轉移到 Else,在那里它改變了你自己的昵稱,而在我的服務器中,我是所有者,我的昵稱不能被機器人改變。 通過重寫 if 語句以在繼續之前專門檢查提及來修復它。 現在工作!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM