1

Hi so I recently started making a discord bot but when I run the node with node Luna.js it gves an error

    } catch{
           ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/root/kuchubot/node_modules/discord.js/src/index.js:8:11)

What Do I do to fix this?

  • oops and this is the directory of the errored code /root/kuchubot/node_modules/discord.js/src/client/Client.js:42 – Ip Logging Boi Mar 28 '21 at 06:16
  • 1
    That should be a left parenthesis instead of a bracket. – John Douma Mar 28 '21 at 06:19
  • 2
    `catch(error) {` – hoangdv Mar 28 '21 at 06:33
  • 2
    What is the version of Node.js? What other code do you have? The code shown *should be* valid and is supported in Node.js version 10.3 and above. [See here](https://stackoverflow.com/a/56001361/). Either your Node version is low or there is another syntax error. – VLAZ Mar 28 '21 at 07:39

1 Answers1

2

You will need to have a () after catch. You don't need to use the error variable, but this should work:

try {
    //code
} catch (error) {
    //error code
}
blaumeise20
  • 2,025
  • 5
  • 22
  • 1
    [Omitting the error parameter is valid](https://jsbin.com/seyikehego/1/edit?js,console) you don't have to have it. – VLAZ Mar 28 '21 at 07:33