it's bugging for me

Cannot use import statement outside of a module
70 Replies
Favna
Favna•2y 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.
Yoozi
YooziOP•2y ago
but it's not in ESM(that's all I have btw)
simxnet
simxnet•2y ago
you mostly are trying to run .ts files you must compile them into js
Yoozi
YooziOP•2y ago
the files names are "index.js" and "ping.js" as the guide said
simxnet
simxnet•2y ago
mmm package.json has type module?
Yoozi
YooziOP•2y ago
yes
Yoozi
YooziOP•2y ago
simxnet
simxnet•2y ago
wait wait show me the entire package.json
Yoozi
YooziOP•2y ago
simxnet
simxnet•2y ago
lolololol you have the type option as a dependency place it below "main"
Yoozi
YooziOP•2y ago
the sapphire framework? ohhh
simxnet
simxnet•2y ago
huh?
Yoozi
YooziOP•2y ago
the type mb
simxnet
simxnet•2y ago
yes
Yoozi
YooziOP•2y ago
now my token is invalid kekw
Yoozi
YooziOP•2y ago
simxnet
simxnet•2y ago
maybe that error was always there but your console only displays one env should be in double quotes TOKEN="token"
Yoozi
YooziOP•2y ago
no I restart my consel everytime I run the bot
simxnet
simxnet•2y ago
not what i said
Yoozi
YooziOP•2y ago
i hate life lebruh
simxnet
simxnet•2y 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?
Yoozi
YooziOP•2y 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 | }
simxnet
simxnet•2y ago
lol atp i dont know it should work unless your .env is on the wrong place
Yoozi
YooziOP•2y ago
wdym
Favna
Favna•2y ago
TOKEN=value works just fine when using dotenv FYI.
simxnet
simxnet•2y ago
that "FYI" looks so hostile 😨
Favna
Favna•2y ago
uhhh really? never saw it as such. Sorry.
simxnet
simxnet•2y ago
npp
Yoozi
YooziOP•2y ago
so I deleted the .env file and pasted the token in index and it omegalul
Favna
Favna•2y ago
that means it wasn't being loaded
simxnet
simxnet•2y ago
yea it couldn't be read
Favna
Favna•2y 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)
simxnet
simxnet•2y ago
i faced the same issue but i changed this and it worked
Favna
Favna•2y ago
it'll read from root then
simxnet
simxnet•2y ago
yep
Favna
Favna•2y 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.
simxnet
simxnet•2y ago
for some reason it wont load on src dir
Favna
Favna•2y ago
we probably had some kind of broken monorepo setup at the time
Favna
Favna•2y ago
it will, I can guarantee it. @Dragonite, @Spinel, @Skyra, @Teryl, @Iriss all load it from src/.env.
simxnet
simxnet•2y ago
mmmmm
Favna
Favna•2y ago
(all those bots are open source btw)
simxnet
simxnet•2y ago
ikik im good with root env tho
Favna
Favna•2y ago
yeah I imagine most people are
Yoozi
YooziOP•2y ago
so I read the guide and I'm still new to the framework so how do I make a CreepySmile
Yoozi
YooziOP•2y ago
I have the ping cmd from thr guide and it doesn't work I'm trying over here
simxnet
simxnet•2y ago
oh
Yoozi
YooziOP•2y ago
my brain is kekw
simxnet
simxnet•2y ago
mmmm you trying slash cmds or message cmds
Yoozi
YooziOP•2y ago
yep
simxnet
simxnet•2y ago
yes what
Yoozi
YooziOP•2y ago
it didn't load the slash so I tried the message one
simxnet
simxnet•2y ago
none works?
Yoozi
YooziOP•2y ago
no
simxnet
simxnet•2y ago
Yoozi
YooziOP•2y ago
oh i didn't load the listeners
simxnet
simxnet•2y ago
exactly
Yoozi
YooziOP•2y ago
can you give me an example on how Sapphire options works
simxnet
simxnet•2y ago
that would take some time, so I would prefer you to read this instead
simxnet
simxnet•2y ago
wait yes that
Yoozi
YooziOP•2y ago
no I meant like where to put them yk like in the options: options yk field?
simxnet
simxnet•2y ago
mmm i dont get it
Favna
Favna•2y ago
new SapphireClient({
loadMessageCommandListeners: true
})
new SapphireClient({
loadMessageCommandListeners: true
})
simxnet
simxnet•2y ago
ah lool
Yoozi
YooziOP•2y ago
should I put it in index or the cmd awkward
Favna
Favna•2y ago
you put it whereever you already have that new SapphireClient now
Spinel
Spinel•2y 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.
Want results from more Discord servers?
Add your server