【问题标题】:trying to add a role when a member joins the server当成员加入服务器时尝试添加角色
【发布时间】:2018-12-13 06:26:33
【问题描述】:

每当我尝试让新成员在我的机器人中扮演角色时,我的机器人都会遇到这个问题。代码如下:

bot.on('guildMemberAdd', member => {
   member.addRole(member.guild.roles.find("name","User"));
});

这是我在新成员加入时遇到的错误:

(node:8308) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at item.request.gen.end (C:\Users\REEE\Downloads\bot\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:71:65)
at then (C:\Users\REEE\Downloads\bot\node_modules\snekfetch\src\index.js:215:21)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:8308) 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(). (rejection id: 2)
(node:8308) [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.

我已经为我的机器人授予了我的服务器的所有权限,但它仍然说它缺少权限。有什么建议吗?

【问题讨论】:

  • 在我看来这是您的 API 没有适当权限的问题,而不是您的服务器中的机器人。为了正确调试,我们需要访问 node.js 部分代码,特别是 next_tick.js 第 188 行和 index.js 第 215 行
  • 尝试将您的机器人角色设置为高于您要分配给用户的角色。

标签: javascript discord.js


【解决方案1】:

这个问题可以通过给你的机器人更高的权限来解决。 “YourBot'sRole”必须高于您要赋予的“用户”角色。并记得检查你的机器人的权限。它可能没有 MANAGE_ROLES 权限。您可以通过服务器设置中的“角色”选项或在您的机器人邀请链接中将权限设置为 8 来完成此操作。 (8是ADMINISTRATOR权限,授予所有权限)

【讨论】:

    【解决方案2】:

    似乎member.addRole(someRole) 不再适用于最新版本的 Discord.js,尽管文档仍然充满了它。

    请改用member.roles.add(someRole)

    此外,您可以通过以下方式检查您的机器人是否可以管理角色:

    if (! member.guild.me.hasPermission('MANAGE_ROLES'))
        return console.error("I don't have the right to manage roles !!!  :-( ");
    

    如果仍然失败,请在您的服务器配置的角色配置页面中,在角色列表中,确保您尝试分配的角色列在您的机器人角色下(您可以拖动角色重新排序)。

    和你一样,我已将所有权限授予我的机器人角色,但它仍然无法正常工作。然后我简单地将我的机器人角色拖到我想自动授予的角色之上,它就起作用了!!!

    如果您有兴趣,我已经输入some more detailed code on how to add a role to a member here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2020-12-11
      • 2021-06-27
      • 2021-11-29
      • 1970-01-01
      • 2021-07-11
      • 2021-01-01
      相关资源
      最近更新 更多