【问题标题】:DiscordAPIError: Unknown roleDiscordAPIError:未知角色
【发布时间】:2020-09-17 08:54:39
【问题描述】:

我试图在 discord.js 中创建一个命令,让机器人找到它可以赋予一个人的最高角色并将其赋予这个人。

      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)

谁能帮我解决这个问题?

【问题讨论】:

    标签: bots discord discord.js


    【解决方案1】:

    您当前的代码没有检查r.rawPosition 是否等于myrole - 1,而是将r.rawPosition 定义为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);
    

    【讨论】:

    • 谢谢!你不会相信我在这里提出问题之前所经历的愤怒。 (而且,这一切都是因为两个等于...)
    猜你喜欢
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 2021-07-07
    • 2021-12-26
    • 2022-01-16
    • 2022-01-21
    • 2021-09-20
    • 1970-01-01
    相关资源
    最近更新 更多