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