NightOwl4321
NightOwl4321

Reputation: 45

Error while attempting to deploy discord bot

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

[email protected] 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!

Upvotes: 0

Views: 110

Answers (2)

Hyunnique
Hyunnique

Reputation: 300

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?.

Upvotes: 2

Nathan
Nathan

Reputation: 11

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

Upvotes: 0

Related Questions