Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a problem, I want to let perform a command only if the user has a specific role but it gives me the error, unexpected { on this rule:
JavaScript
if (message.member.roles.has(allowedRole.id) {

Can someone help me with my problem?
JavaScript
<pre>let allowedRole = message.guild.roles.find("name", "rolename");
    if (message.member.roles.has(allowedRole.id) {
      client.on('message', message => {

        if (!message.guild) return;
        if (message.content.startsWith(prefix + 'kick')) {
          const user = message.mentions.users.first();
          if (user) {
            const member = message.guild.member(user);
            if (member) {
              member
                .kick(' ')
                .then(() => {

                  message.reply(`Successfully kicked ${user.tag}`);
                })
                .catch(err => {
                  message.reply('I was unable to kick the member');
                  console.error(err);
                });
            } else {
              message.reply("That user isn't in this guild!");
            }
          } else {
            message.reply("You didn't mention the user to kick!");
          }
        }
      });
    } else {
      	console.log("You don't have the permission to kick users!")
    })


edit:

I guess it is in this rule:
JavaScript
if (message.member.roles.has(allowedRole.id) { 

With the first round bracket, it says that it is not ending but it is...

edit:

JavaScript
client.on('message', message => {
  if (!message.guild) return;

  if (message.content.startsWith('!kick')) {
    const user = message.mentions.users.first();
    if (user) {
      const member = message.guild.member(user);
      if (member) {
        member
          .kick('Optional reason that will display in the audit logs')
          .then(() => {
            message.reply(`Successfully kicked ${user.tag}`);
          })
          .catch(err => {
            message.reply('I was unable to kick the member');
            console.error(err);
          });
      } else {
        message.reply("That user isn't in this guild!");
      }
    } else {
      message.reply("You didn't mention the user to kick!");
    }
  }
});


Somewehere has to come that error message with you don't have the permission, but i don't know where..

Thanks,
Sam

What I have tried:

I tried to search internet but the solution that is provided is not working for me. Because I do something wrong but cannot figure out what!
Posted
Updated 1-Nov-20 23:25pm
v3
Comments
Peter_in_2780 1-Nov-20 18:46pm    
For starters, count brackets (or use an editor that matches them).
Take a hard look at the line the causes the error.
Sam Vorst 2-Nov-20 2:40am    
I installed one in atom which colors the brackets, and I guess I find the problem it is in round bracket. Only I don't know how to solve it. I will mark the problem that is guess in the original question.


1 solution

Look at your code:
if (message.member.roles.has(allowedRole.id) {
   ^
   |
    -- where is the matching close bracket?
Try:
if (message.member.roles.has(allowedRole.id)) {
                                            ^
                                            |
                              Add this -----
 
Share this answer
 
v2
Comments
Sam Vorst 2-Nov-20 5:20am    
It worked but now i got another issue, I can't give an error message to the user that is has no permissions. Because I don't know where to place it. I change the code in the main question so you can take a look.
OriginalGriff 2-Nov-20 5:31am    
Different issue needs a different question: Answered questions get less views (and thus responses) than new ones.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900