如何从用户中删除所有角色?

时间:2018-11-04 00:05:29

标签: permissions discord.js

我试图发出一个挂起的命令,并且使角色起作用的唯一方法是将所有其他角色从用户中删除。当我不一致地执行命令时,它会将其吐出到控制台中,表示当机器人和用户都拥有它们时,它没有权限:

> C:\Users\dubwi\Desktop\LDU_Bot>node .
Ready
(node:16868) DeprecationWarning: Collection#find: pass a function instead
{ DiscordAPIError: Missing Permissions
    at item.request.gen.end (C:\Users\dubwi\Desktop\LDU_Bot\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:79:15)
    at then (C:\Users\dubwi\Desktop\LDU_Bot\node_modules\snekfetch\src\index.js:215:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  name: 'DiscordAPIError',
  message: 'Missing Permissions',
  path:
   '/api/v7/guilds/418505146876559371/members/311651448519786496',
  code: 50013,
  method: 'PATCH' }
case "suspend":
  if (message.member.hasPermission('MANAGE_ROLES')) {
    let rMember = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0])); //Gets the user
    if (!rMember) return message.reply("That user does not exist.");
    let gRole = message.guild.roles.find('name', 'SUSPENDED'); //Gets the SUSPENDED role

    rMember.removeRoles(rMember.roles).then(console.log).catch(console.error); //Removes all roles
    rMember.addRole(gRole.id); //Adds suspended Role


    message.channel.send("User was suspended."); //Messages the channel that the user was suspended

    try {
      await rMember.send("You have been suspended."); //Tries to DM User
    } catch (e) {
      message.channel.send("We tried to DM the user to let them know, but their DM's are locked."); //Announces that their DMs are locked
    }


  } else {
    message.channel.send("You do not have permission to use this command.");
  }
  break;

1 个答案:

答案 0 :(得分:0)

如您的错误代码所述,您缺少权限;

  

DiscordAPIError:缺少权限

这意味着漫游器缺少执行removeRoles()功能所需的权限。