亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在不和諧中更改昵稱時缺少權限錯誤.js

在不和諧中更改昵稱時缺少權限錯誤.js

Cats萌萌 2022-08-18 16:08:32
每次我嘗試使用我的機器人更改服務器中其他人的昵稱(甚至是朋友的服務器中的我自己),它都會失敗,給我帶來以下錯誤:(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 handledwith .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.我檢查了一下,它確實有管理昵稱,它的角色就在所有者下面。我試圖改變昵稱的人,他的最高角色遠遠低于機器人。機器人的角色、職位和管理昵稱權限的圖像。代碼如下: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;    }    });怎么了?這是一個小故障嗎?角色中是否有問題?還是我的代碼有問題?
查看完整描述

2 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

好消息!您的代碼不是問題所在。問題在于機器人角色的定位方式以及它擁有的權限。確保機器人能夠更改其他人的姓名,并且其角色高于受害者的角色。希望這有幫助!

http://img1.sycdn.imooc.com//62fdf3ac00018d1e04260055.jpg

將其打開

http://img1.sycdn.imooc.com//62fdf3b5000198b904160063.jpg

查看完整回答
反對 回復 2022-08-18
?
絕地無雙

TA貢獻1946條經驗 獲得超4個贊

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


查看完整回答
反對 回復 2022-08-18
  • 2 回答
  • 0 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號