简体   繁体   中英

When I put node .\index I get the error (error Uncaught SyntaxError: Invalid or unexpected token)

This is my code and I'm trying to make a discord bot to learn about coding and I don't know. What to do because this is my first project

const Discord = require('discord.js');
const client = new Discord.client();

client.once('ready', () => {
    console.log('Ready!');
});

client.login('NzQ3MTQzNzczNDY0NTU5NzE2.X0Kl3A.86aCrGafWyTORGVVSTcyDS4bqlY');

the error that i get when i just put node index.js is

internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module '[discord.js'
Require stack:
- C:\Users\Joey\Desktop\dsbot\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)

    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\Joey\Desktop\dsbot\index.js:1:17)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\Joey\\Desktop\\dsbot\\index.js' ]
} 

the new error i get is

C:\Users\Joey\Desktop\dsbot\index.js:2
const client = new Discord.client();
               ^

TypeError: Discord.client is not a constructor
    at Object.<anonymous> (C:\Users\Joey\Desktop\dsbot\index.js:2:16)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)

    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

the newest error

(node:18644) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
    at WebSocketManager.connect (C:\Users\Joey\Desktop\dsbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:133:26)
    at Client.login (C:\Users\Joey\Desktop\dsbot\node_modules\discord.js\src\client\Client.js:222:21)
(node:18644) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not
handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (reje
ction id: 1)
(node:18644) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I believe the command you're looking for is:

node index.js

Also, I agree with the comments. Never post your token online. People will be able to log into your bot and do/say whatever they want. Luckily Discord is pretty good about this, and have probably automatically reset your token by now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM