it's bugging for me

Cannot use import statement outside of a module
70 Replies
Favna
Favna•12mo ago
Choose between using ESM and CJS, don't try to use ESM code in a CJS setup. Whatever you did with your code, that's your problem.
Vanilla
Vanilla•12mo ago
but it's not in ESM(that's all I have btw)
Belize
Belize•12mo ago
you mostly are trying to run .ts files you must compile them into js
Vanilla
Vanilla•12mo ago
the files names are "index.js" and "ping.js" as the guide said
Belize
Belize•12mo ago
mmm package.json has type module?
Vanilla
Vanilla•12mo ago
yes
Vanilla
Vanilla•12mo ago
Belize
Belize•12mo ago
wait wait show me the entire package.json
Vanilla
Vanilla•12mo ago
Belize
Belize•12mo ago
lolololol you have the type option as a dependency place it below "main"
Vanilla
Vanilla•12mo ago
the sapphire framework? ohhh
Belize
Belize•12mo ago
huh?
Vanilla
Vanilla•12mo ago
the type mb
Belize
Belize•12mo ago
yes
Vanilla
Vanilla•12mo ago
now my token is invalid kekw
Vanilla
Vanilla•12mo ago
Belize
Belize•12mo ago
maybe that error was always there but your console only displays one env should be in double quotes TOKEN="token"
Vanilla
Vanilla•12mo ago
no I restart my consel everytime I run the bot
Belize
Belize•12mo ago
not what i said
Vanilla
Vanilla•12mo ago
i hate life lebruh
Belize
Belize•12mo ago
e.g: if you have 4 errors, console will only display the first once the first is solved, it'll show the second one yk solved?
Vanilla
Vanilla•12mo ago
0|index | at async link (node:internal/modules/esm/module_job:67:21)
0|index | Error [TokenInvalid]: An invalid token was provided.
0|index | at _SapphireClient.login (/root/node_modules/discord.js/src/client/Client.js:214:52)
0|index | at _SapphireClient.login (/root/node_modules/@sapphire/framework/dist/lib/SapphireClient.js:79:31) {
0|index | code: 'TokenInvalid'
0|index | }
0|index | Error when loading '/root/commands/ping.js': SyntaxError: Unexpected token '{'
0|index | at DefaultModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18)
0|index | at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:203:14)
0|index | at async link (node:internal/modules/esm/module_job:67:21)
0|index | Error [TokenInvalid]: An invalid token was provided.
0|index | at _SapphireClient.login (/root/node_modules/discord.js/src/client/Client.js:214:52)
0|index | at _SapphireClient.login (/root/node_modules/@sapphire/framework/dist/lib/SapphireClient.js:79:31) {
0|index | code: 'TokenInvalid'
0|index | }
0|index | at async link (node:internal/modules/esm/module_job:67:21)
0|index | Error [TokenInvalid]: An invalid token was provided.
0|index | at _SapphireClient.login (/root/node_modules/discord.js/src/client/Client.js:214:52)
0|index | at _SapphireClient.login (/root/node_modules/@sapphire/framework/dist/lib/SapphireClient.js:79:31) {
0|index | code: 'TokenInvalid'
0|index | }
0|index | Error when loading '/root/commands/ping.js': SyntaxError: Unexpected token '{'
0|index | at DefaultModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18)
0|index | at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:203:14)
0|index | at async link (node:internal/modules/esm/module_job:67:21)
0|index | Error [TokenInvalid]: An invalid token was provided.
0|index | at _SapphireClient.login (/root/node_modules/discord.js/src/client/Client.js:214:52)
0|index | at _SapphireClient.login (/root/node_modules/@sapphire/framework/dist/lib/SapphireClient.js:79:31) {
0|index | code: 'TokenInvalid'
0|index | }
Belize
Belize•12mo ago
lol atp i dont know it should work unless your .env is on the wrong place
Vanilla
Vanilla•12mo ago
wdym
Favna
Favna•12mo ago
TOKEN=value works just fine when using dotenv FYI.
Belize
Belize•12mo ago
that "FYI" looks so hostile 😨
Favna
Favna•12mo ago
uhhh really? never saw it as such. Sorry.
Belize
Belize•12mo ago
npp
Vanilla
Vanilla•12mo ago
so I deleted the .env file and pasted the token in index and it omegalul
Favna
Favna•12mo ago
that means it wasn't being loaded
Belize
Belize•12mo ago
yea it couldn't be read
Favna
Favna•12mo ago
as for the location of the env file, it depends on how you setup dotenv yeah. If using the examples from the CLI it should be src/.env[.environment][.local] (see https://github.com/skyra-project/archid-components/tree/main/packages/env-utilities#what-env-files-can-be-used)
Belize
Belize•12mo ago
i faced the same issue but i changed this and it worked
Favna
Favna•12mo ago
it'll read from root then
Belize
Belize•12mo ago
yep
Favna
Favna•12mo ago
tbh I don't even know why Kyra and I defaulted to src/.env way way long ago but it now propegates to sapphire examples.
Belize
Belize•12mo ago
for some reason it wont load on src dir
Favna
Favna•12mo ago
we probably had some kind of broken monorepo setup at the time
Favna
Favna•12mo ago
it will, I can guarantee it. @Dragonite, @Spinel, @Skyra, @Teryl, @Iriss all load it from src/.env.
Belize
Belize•12mo ago
mmmmm
Favna
Favna•12mo ago
(all those bots are open source btw)
Belize
Belize•12mo ago
ikik im good with root env tho
Favna
Favna•12mo ago
yeah I imagine most people are
Vanilla
Vanilla•12mo ago
so I read the guide and I'm still new to the framework so how do I make a CreepySmile
Vanilla
Vanilla•12mo ago
I have the ping cmd from thr guide and it doesn't work I'm trying over here
Belize
Belize•12mo ago
oh
Vanilla
Vanilla•12mo ago
my brain is kekw
Belize
Belize•12mo ago
mmmm you trying slash cmds or message cmds
Vanilla
Vanilla•12mo ago
yep
Belize
Belize•12mo ago
yes what
Vanilla
Vanilla•12mo ago
it didn't load the slash so I tried the message one
Belize
Belize•12mo ago
none works?
Vanilla
Vanilla•12mo ago
no
Belize
Belize•12mo ago
Vanilla
Vanilla•12mo ago
oh i didn't load the listeners
Belize
Belize•12mo ago
exactly
Vanilla
Vanilla•12mo ago
can you give me an example on how Sapphire options works
Belize
Belize•12mo ago
that would take some time, so I would prefer you to read this instead
Belize
Belize•12mo ago
wait yes that
Vanilla
Vanilla•12mo ago
no I meant like where to put them yk like in the options: options yk field?
Belize
Belize•12mo ago
mmm i dont get it
Favna
Favna•12mo ago
new SapphireClient({
loadMessageCommandListeners: true
})
new SapphireClient({
loadMessageCommandListeners: true
})
Belize
Belize•12mo ago
ah lool
Vanilla
Vanilla•12mo ago
should I put it in index or the cmd awkward
Favna
Favna•12mo ago
you put it whereever you already have that new SapphireClient now
Spinel
Spinel•12mo ago
Before you make a Discord Bot, you should have a good understanding of JavaScript. This means you should have a basic understanding of the following topics: - Read and understand docs - Debug code - Syntax - NodeJS module system If you aren't sure that your understanding of JavaScript is truly good enough to make a bot, you should really try to continue learning first. Here are good resources to learn both Javascript and NodeJS: Codecademy: https://www.codecademy.com/learn/javascript Udemy: https://www.udemy.com/javascript-essentials/ Eloquent JavaScript, free book: http://eloquentjavascript.net/ You-Dont-Know-JS: https://github.com/getify/You-Dont-Know-JS JavaScript Garden: https://bonsaiden.github.io/JavaScript-Garden/ JavaScript reference/docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference Nodeschool: https://nodeschool.io/ Pluralsight: https://www.codeschool.com/courses/real-time-web-with-node-js Before you ask a question, you should ask these yourself: 1) Is this question related to JavaScript, or the library I am using? - If it is the library you are using, go to the proper server. You would get better answers there. 2) Have I tried to google and / or check StackOverflow? - Double check that you can't find anywhere that can lead you to a solution online. 3) Have I tried to look on MDN or the library documentation? - You should always check documentations to make sure you aren't missing how any details. 4) Does my question make enough sense so that people can understand it, and do they understand what I am trying to accomplish? - If no, revise your question. Give as much detail as possible. Include any error or code output that can help us help you. 5) Am I aware of what I am doing, and not just mindlessly copy and pasting? - If you are just copy and pasting code from a guide, you are not going to be able to solve anything. Make sure you understand the code you are writing.