0
votes

So I was trying to code my bot to add a role to someone who doesn't have that role.... the rest of the code was working fine until I added the member.roles.add command.

It says Missing Permission however the bot has every possible permission on the server.

module.exports = {
    name: 'ping',
    description: "this is a ping command!",
    execute(message, args) {
        if (message.member.roles.cache.has('754222099219873974')) {
            message.channel.send('pong');
        }
        else {
            message.channel.send('I see you do not have the right permission to use that command, let me change that for you :)');
            message.member.roles.add('754222099219873974');
        }

    }
}

This is the entire code for one command.

Below is the error I get from the command terminal

(node:68344) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions at RequestHandler.execute (C:\Users\Amit\Desktop\Discord\node_modules\discord.js\src\rest\RequestHandler.js:170:25) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:68344) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:68344) [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.

1
Can you explain what you mean by the code not working? Are you getting an error? What behavior specifically results from the code you've posted? - Allister
the message "I see you do not have........." appears in the server......However it doesnt add the role............ The console gives me this error>>> - AtulRy
You cannot add a role if the role is above the bot's role in hierarchy - Lioness100
@Lioness100 but the bot has all the permissions including administrator active whereas ..... the role has a very few permissions - AtulRy
@Lioness100 whoa ok i got it........ i didnt know that the order mattered......... thanks a lot......appreciate it...... - AtulRy

1 Answers

0
votes

Hey Guys I've solved the issue!

I didn't know that this order really mattered:

I didn't know that this order really mattered

The issue was that the bot was placed below the role i wanted to implement All I had to do was drag the bot above the role and then it worked fine.

Thanks a lot!!! CHEERS!!