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