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
- 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.I thank your cooldown system should be inside your interactionCreate listener
well, it is
its in interactionCreate
but i cant start main.js
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
so, i just have to put it in main.js if im getting you right ?
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
Agh, i dont know how to explain, the only thing in main.js is client.cooldowns, the rest of stuff is in interactionCreate
You can do the cooldown logic in your main.js yes, but you cant magically destructure it from a nonexistent property
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
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 inso, uhh, what should i do ?
i have to make it start along with the bot or what ?
no, you need to move the code for handling command cooldowns where you actually handle commands: inside the
execute
functionso, i have to put some part of code into main.js, the file i execute ?
right ?
no
a
please take note of the function in the green box
and its name
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
Yes but that wont still work because it's based onna command.data property, which i dont see anywhere
Lemme see
Personally i'd put it in my event handler before when you call the execute function
Its there
since i assume your client.commands has it set
Its not though
Wait
Here
Yeah mb i thought that was a command, not your interactionCreate
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
propertiesyeah i though they were showing their command, didnt see the event
So, will it work ?
Or i have to do something else ?
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 commandphew, i finally got the connection, and, it worked!
lemme check the cooldowns in discord
the application did not respond 💀
care to share your updated code?
do you receive any errors in your console?
no errors at all
imma send the code
Here is interactionCreate.js
i put the cooldowns code into execute func
right ?
yes
you should be receiving an error with this code
funny
could you log something at the top of the
execute
function?well, i put few sentences at the top
got the error
that's not exactly what I asked you to do
umm
i dont get it
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.
a
understood
and when I say "the top of the
execute
function", I mean like right before const { cooldowns } = client
like this ?
sure
well, it didnt write "123"
ig it means that bot went online, but the intetactionCreate thing didnt work at all and didnt show me the error
this is pretty basic js at this point
There is no client.log
Its console.log
bruh
my bad
xD
k, fixed this thing
still didnt write anything
then the execute loop isnt being called at all
as it would throw an error
ye, right, but why ?
Because you access command.data before defining it
what do you mean ? firsly i defined cooldowns and then wrote command.data thing
Yes, but you never define command
a
now i get it
This is basic js at this point
or rather it's later in the code
i dont understand which of parametres are discord.js stuff or my own, my bad
like this ?
you still need to accessinteraction.client
as opposed to an undefinedclient
but why is client still undefined ?
Because you dont define it
You have to access it from interaction.client
its defined in main.js
That doesnt make it global
a
Just because you define it there doesnt mean you can access it anywhere
i thought it does
so, i have to define it again ?
I'd recommend checking out #resources as you seem to be struggling with the basic concepts
ye, you are right
i dont know anything about js
srry for wasting your time
and big thanks for help