0

I am trying to create a discord bot following this tutorial. However, when I try to deploy the bot using npm run dev I get

my-bot@1.0.0 dev /mnt/c/Users/kkmin/Documents/src/ees
 nodemon index.js

[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
/mnt/c/Users/kkmin/Documents/src/ees/node_modules/discord.js/src/client/Client.js:40
    } 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> (/mnt/c/Users/kkmin/Documents/src/ees/node_modules/discord.js/src/index.js:8:11)
[nodemon] app crashed - waiting for file changes before starting...

I'm not sure what's wrong, and I'm very new to this, could someone please help me. Thanks in advance!

NightOwl4321
  • 45
  • 1
  • 1
  • 8

2 Answers2

2

I think you are using old Node.js versions.

Optional Catch Binding

try ... catch without identifier is called "Optional Catch Binding", It is introduced at ES2019, and available at Node.js >= 10.3.0 (see node.green).

To use that function, Update your Node.js with latest release, follow How do I update Node.js?.

Hyunnique
  • 300
  • 1
  • 10
  • 1
    @NightOwl4321 did you updated your node inside of WSL? I have no idea about your environment but if you use Linux for your server, you need to update your node.js at linux not at windows. – Hyunnique Mar 20 '20 at 05:09
0

You have a syntax error in your Client.js file. You are attempting to do a try-catch block, but you have implemented it incorrectly. The catch block takes one argument, which represents the error. Please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch

Nathan
  • 11
  • 2