Reputation: 31
I've been having this issue with my bot whenever I try to give a new member a role with my bot. Here is the code:
bot.on('guildMemberAdd', member => {
member.addRole(member.guild.roles.find("name","User"));
});
Here is the error I get when a new member joins:
(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.
I've given my bot every permission for my server, and yet it still says that it's missing the permissions. Any tips?
Upvotes: 3
Views: 1724
Reputation: 939
It seems that member.addRole(someRole)
does not work anymore with the latest version of Discord.js, although the documentation is still full of it.
Please use member.roles.add(someRole)
instead.
Also, you can check your bot can manage roles with:
if (! member.guild.me.hasPermission('MANAGE_ROLES'))
return console.error("I don't have the right to manage roles !!! :-( ");
Then if that still fails, in the role configuration page of your server configuration, in the role list, make sure the role you are trying to attribute, is listed under the role of your bot (you can drag the roles to re-order them).
Like you, I had given ALL privileges to my bot's role, and it still wouldn't work. Then I simply dragged my bot's role above the role I wanted to automatically grant, and it worked!!!
I've put some more detailed code on how to add a role to a member here if you are interested.
Upvotes: 0
Reputation: 384
This problem can be solved by giving your bot higher permissions than the permission you will give. "YourBot'sRole" must be higher than that "User" role you are going to give. And remember to check your bot's permissions. It might not have MANAGE_ROLES permission. You can simply get this done by "Roles" option in Server Settings or setting permission to 8 in your bot's invite link. (8 is ADMINISTRATOR access, grants all permissions)
Upvotes: 1