0
votes

I'm trying to delete an already created role with the discord bot using discord.js.

The error in terminal shows:

DiscordAPIError: Missing Permissions

Although I have given my bot all permissions.

Code: guild.roles.find(role => role.name === 'Test').delete();

Error message in terminal:
(node:7428) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions at item.request.gen.end (...\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15) at then (...\node_modules\snekfetch\src\index.js:215:21) at process._tickCallback (internal/process/next_tick.js:68:7) (node:7428) 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:7428) [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.

2
Please let us know if the answer posted below works for you or not. Would be helpful for future users.jerseyetr
If he says that he gave the bot the necessary permissions, there is nothing else that would return that error.Timesis

2 Answers

1
votes

Although your bot may have the necessary permissions to delete roles, due to the way Discord's Role Hierarchy system works, your bot will ALSO need to be higher (above linearly) in the roles list.

If you plan on having a role delete feature, I'd recommend putting the bot's role to the top of the list, or at least, above any potential role that would need to be deleted.

More information on the role hierarchy can be found here

0
votes

I was trying to delete it like shown above when he was kicked from a server. I've tried to delete it by a command like this:

message.guild.roles.find(role => role.name === 'Test').delete();

It was deleted, so just make sure that bot has right permissions to delete roles and bot's role is above the role that is supposed to be deleted. I still need to figure out how to correctly reference the guild in this command:

guild.roles.find(role => role.name === 'Test').delete();