client is not defined in interactionCreate.js, but it is defined in main.js

If im not wrong, i dont have to defind it again ;=;
72 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers.
Syjalo
Syjalo12mo ago
I thank your cooldown system should be inside your interactionCreate listener
Suspicious Man
Suspicious Man12mo ago
well, it is its in interactionCreate but i cant start main.js
treble/luna
treble/luna12mo ago
it is not, you destructure it from client, but you never declare client outside of your execute loop so destructure inside your execute loop, and destructure from interaction.client
Suspicious Man
Suspicious Man12mo ago
so, i just have to put it in main.js if im getting you right ?
treble/luna
treble/luna12mo ago
no destructure inside your interactionCreate loop You can leave client.cooldowns defined in your main file But you have to access it from the client in your execute loop
Suspicious Man
Suspicious Man12mo ago
Agh, i dont know how to explain, the only thing in main.js is client.cooldowns, the rest of stuff is in interactionCreate
treble/luna
treble/luna12mo ago
You can do the cooldown logic in your main.js yes, but you cant magically destructure it from a nonexistent property
Suspicious Man
Suspicious Man12mo ago
Well, i just did all like the guide says, i put client.cooldowns = new Collection(); in main.js and other stuff i put in interactionCreate.js I cant put it in there, bc its already there
duck
duck12mo ago
the idea is you can't just put it in the file interactionCreate.js it's not just the code's presence in the file that makes it execute when the event is received the execute function is what executes when the event is received the erroring code is currently outside this function currently it will also presumably execute immediately before the bot even logs in
Suspicious Man
Suspicious Man12mo ago
so, uhh, what should i do ? i have to make it start along with the bot or what ?
duck
duck12mo ago
no, you need to move the code for handling command cooldowns where you actually handle commands: inside the execute function
Suspicious Man
Suspicious Man12mo ago
so, i have to put some part of code into main.js, the file i execute ? right ?
duck
duck12mo ago
no
Suspicious Man
Suspicious Man12mo ago
a
duck
duck12mo ago
duck
duck12mo ago
please take note of the function in the green box and its name
Suspicious Man
Suspicious Man12mo ago
Sorry, ive lost my internet connection, im back So, i have to move the red part into green part ? Sorry, I couldn’t understand what you meant by execute function, thanks for explanation Agh, i still dont have internet connection, imma write when i can try the code
treble/luna
treble/luna12mo ago
Yes but that wont still work because it's based onna command.data property, which i dont see anywhere
Suspicious Man
Suspicious Man12mo ago
Lemme see
treble/luna
treble/luna12mo ago
Personally i'd put it in my event handler before when you call the execute function
Suspicious Man
Suspicious Man12mo ago
Its there
treble/luna
treble/luna12mo ago
since i assume your client.commands has it set Its not though Wait
Suspicious Man
Suspicious Man12mo ago
Here
Suspicious Man
Suspicious Man12mo ago
treble/luna
treble/luna12mo ago
Yeah mb i thought that was a command, not your interactionCreate
duck
duck12mo ago
they haven't shown any of their commands in this thread they're following the guide, and from what I remember their commands do have data properties
treble/luna
treble/luna12mo ago
yeah i though they were showing their command, didnt see the event
Suspicious Man
Suspicious Man12mo ago
So, will it work ? Or i have to do something else ?
duck
duck12mo ago
you still need to access interaction.client as opposed to an undefined client and you should probably specifically put this after you get the command since the cooldown is per command and you need the command in order to differentiate by command
Suspicious Man
Suspicious Man12mo ago
phew, i finally got the connection, and, it worked! lemme check the cooldowns in discord the application did not respond 💀
duck
duck12mo ago
care to share your updated code? do you receive any errors in your console?
Suspicious Man
Suspicious Man12mo ago
no errors at all imma send the code
Suspicious Man
Suspicious Man12mo ago
Here is interactionCreate.js
Suspicious Man
Suspicious Man12mo ago
i put the cooldowns code into execute func right ?
duck
duck12mo ago
yes you should be receiving an error with this code
Suspicious Man
Suspicious Man12mo ago
funny
duck
duck12mo ago
could you log something at the top of the execute function?
Suspicious Man
Suspicious Man12mo ago
well, i put few sentences at the top got the error
Suspicious Man
Suspicious Man12mo ago
duck
duck12mo ago
that's not exactly what I asked you to do
Suspicious Man
Suspicious Man12mo ago
umm i dont get it
d.js docs
d.js docs12mo ago
mdn console: log() method The console.log() method outputs a message to the web console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.
Suspicious Man
Suspicious Man12mo ago
a understood
duck
duck12mo ago
and when I say "the top of the execute function", I mean like right before const { cooldowns } = client
Suspicious Man
Suspicious Man12mo ago
like this ?
duck
duck12mo ago
sure
Suspicious Man
Suspicious Man12mo ago
well, it didnt write "123"
Suspicious Man
Suspicious Man12mo ago
ig it means that bot went online, but the intetactionCreate thing didnt work at all and didnt show me the error
treble/luna
treble/luna12mo ago
this is pretty basic js at this point There is no client.log Its console.log
Suspicious Man
Suspicious Man12mo ago
bruh my bad xD k, fixed this thing still didnt write anything
treble/luna
treble/luna12mo ago
then the execute loop isnt being called at all as it would throw an error
Suspicious Man
Suspicious Man12mo ago
ye, right, but why ?
treble/luna
treble/luna12mo ago
Because you access command.data before defining it
Suspicious Man
Suspicious Man12mo ago
what do you mean ? firsly i defined cooldowns and then wrote command.data thing
Suspicious Man
Suspicious Man12mo ago
treble/luna
treble/luna12mo ago
Yes, but you never define command
Suspicious Man
Suspicious Man12mo ago
a now i get it
treble/luna
treble/luna12mo ago
This is basic js at this point
duck
duck12mo ago
or rather it's later in the code
Suspicious Man
Suspicious Man12mo ago
i dont understand which of parametres are discord.js stuff or my own, my bad
Suspicious Man
Suspicious Man12mo ago
like this ?
duck
duck12mo ago
you still need to access interaction.client as opposed to an undefined client
Suspicious Man
Suspicious Man12mo ago
but why is client still undefined ?
treble/luna
treble/luna12mo ago
Because you dont define it You have to access it from interaction.client
Suspicious Man
Suspicious Man12mo ago
its defined in main.js
treble/luna
treble/luna12mo ago
That doesnt make it global
Suspicious Man
Suspicious Man12mo ago
a
treble/luna
treble/luna12mo ago
Just because you define it there doesnt mean you can access it anywhere
Suspicious Man
Suspicious Man12mo ago
i thought it does so, i have to define it again ?
treble/luna
treble/luna12mo ago
I'd recommend checking out #resources as you seem to be struggling with the basic concepts
Suspicious Man
Suspicious Man12mo ago
ye, you are right i dont know anything about js srry for wasting your time and big thanks for help