it's bugging for me

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

Did you find this page helpful?