本文介绍了DiscordAPIError:未知角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在discord.js中发出一条命令,使该机器人找到它可以赋予某人的最高角色并将其赋予该人.

I was trying to make a command in discord.js in which the bot finds the highest role it can give to a person and gives it to the person.

      const myrole = message.guild.me.roles.highest.rawPosition
      const therole = message.guild.roles.cache.find(r => r.rawPosition = myrole-1)
      const person = message.guild.member(client.users.cache.get("the id"))
      person.roles.add(therole.id);

然后出现以下错误:

    (node:18926) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Role
        at RequestHandler.execute (/rbd/pnpm-volume/d8568466-4a2a-4c3a-ac47-cee06cded9bb/node_modules/.registry.npmjs.org/discord.js/12.2.0/node_modules/discord.js/src/rest/RequestHandler.js:170:25)
        at processTicksAndRejections (internal/process/task_queues.js:88:5)

有人可以帮我吗?

推荐答案

您当前的代码没有检查 r.rawPosition 是否等于它定义的 myrole-1 r.rawPosition 作为 myrole-1

Your current code is not checking if r.rawPosition is equal to myrole - 1 it is defining r.rawPosition as myrole - 1

const myrole = message.guild.me.roles.highest.rawPosition
const therole = message.guild.roles.cache.find(r => r.rawPosition === myrole-1)
const person = message.guild.member(client.users.cache.get("the id"))
person.roles.add(therole.id);

这篇关于DiscordAPIError:未知角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 16:30