user16012290
user16012290

Reputation:

SyntaxError: Missing catch or finally after try ,Discord.js

I am missing catch or finally after try what should I try in catch I don't understand what to add in catch. mute.js:

module.exports = {
    name: 'mute',
    category: 'moderation',
    description: 'This will mute a user of your choice in this server',
    async execute(msg, args) {
    if (msg.member.hasPermission('KICK_MEMBERS')){
        const mutedRole = message.guild.roles.cache.find(
    (role) => role.name === 'Muted'
    );

    if (!mutedRole)
 return message.channel.send('There is no Muted role on this server');

     target.roles.add(mutedRole);

     setTimeout(() => {
  target.roles.remove(mutedRole); // remove the role
  }, mssetTimeout()) 
        const member = msg.mentions.users.first();
            if (!member) return msg.channel.reply(`*You couldn\'t ${this.name} that member!*`);
            try {
                msg.guild.members.cache.get(member.id).ban();
                msg.channel.send(`User has been ${this.name}ed.`);
        }


        }
    } else {
        msg.reply('You do not have access to this command')
    }
      },
    };

Here is my error:

/usr/src/app/commands/mute.js:24
        }
        ^

SyntaxError: Missing catch or finally after try
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/usr/src/app/bot.js:28:21)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

If you think of a catch that should be added in my mute command I am an amature programmer with very bad skills in it shat is something I should add in it.

Upvotes: 0

Views: 619

Answers (1)

Skulaurun Mrusal
Skulaurun Mrusal

Reputation: 2847

From the MDN docs (how try - catch structure looks like):

try {
  // try_statements - The statements to be executed.
}
catch (exception_var) {
  // catch_statements - Statement that is executed if an exception is thrown 
  // in the try-block.
}
finally {
  // finally_statements - Statements that are executed after the try statement completes.
  // These statements execute regardless of whether an exception was thrown or caught. 
}

Now the important part:

The try statement consists of a try-block, which contains one or more statements. {} must always be used, even for single statements. At least one catch-block, or a finally-block, must be present. This gives us three forms for the try statement:

  • try...catch
  • try...finally
  • try...catch...finally

You can't have a try block wihout a catch or finally. So in your code add one of those, even if you leave the body ({}) empty.

Upvotes: 2

Related Questions