#I'm trying to make a discord bot but I'm getting errors.

6 messages · Page 1 of 1 (latest)

dapper frost
#

https://github.com/CodingTrain/Discord-Bot-Examples/tree/main/01-discordjs

I downloaded this code and updated the env file, but I can't find the error?

host@host:/home/bot$ node .
/home/bot/bot.js:2
import { Client, Events, GatewayIntentBits } from 'discord.js';
^

SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

GitHub

Bot Examples for Fall 2023. Contribute to CodingTrain/Discord-Bot-Examples development by creating an account on GitHub.

autumn mortar
#

which version of node.js are you using?

dapper frost
#

I'm trying to make a discord bot but I'm getting errors.

dapper frost
dapper frost
# autumn mortar which version of node.js are you using?

root@host:/home/bot# node bot.js
(node:353236) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use node --trace-warnings ... to show where the warning was created)
/home/bot/bot.js:2
import { Client, Events, GatewayIntentBits } from 'discord.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:77:18)
at wrapSafe (node:internal/modules/cjs/loader:1288:20)
at Module._compile (node:internal/modules/cjs/loader:1340:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49

Node.js v20.11.1

now it gave another error

autumn mortar
#

In your package.json, you need to add "type": "module" to use ES Modules, as the error suggests.