intellisense not working
when i write
inv.
it doesnt follow up with any suggestions, like url
for example59 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.
- Issue solved? Press the button!@Danial here yeah?
Yep
https://sourceb.in/UxJtRTCwdr
alright heres the code. ignore the slash command builder, i was making a command and then just switched up and started trying to fix intellisense
could you go to the console.log statement, and try to
console.log(inv.url);
?
when i write inv.
it doesnt follow up with any suggestions, like url
for example
[email protected], node v18.16.1
no error
code sent
issue: described aboveWhat type does it show when you hover over interaction.channel?
which word specifically? interaction or channel
channel
(property)BaseInteraction<CacheType>.channel: TextBasedChannel | null
TextBasedChannel
no
BaseInteraction is the type
?
does it say smt different for you 🤔
Yep, shows the same for me, what's weird is when I do channel. it shows createInvite, and I let it autocomplete and it shows this but then when I hover over createInvite(), it shows any
yep same here
i have all the autocomplete options for channel, but when i hover over createInvite() it shows any aswell
I've worked with JSDoc a bit but not much so I am not sure what's going on, it's been a while since I used JavaScript, I usually work with TypeScript, I'd recommend you look into TypeScript eventually as then it'd be a much nicer experience
discord.js is very well typed, and will eventually be rewritten in TypeScript
oh ok np then
thanks for the help though
Of course
for now i want to stay in JS ngl, so idk if ill be switching to typescript
is there a way to get other people in here?
simply because all the tutorials im seeing are in JS
This channel's public but as no one has interacted with it, it only shows us in the members list
👌
appreciate the help thanks
You shouldn't rely on tutorials, they also get oudated very soon, there's amazing documentation that can help you come up with things on your own
oh yeah im using the djs docs for my main source of learning
Awesome
uh
adding
/** @type {Invite} */
directly above the inv variable made the intellisense work for it
am i gonna have to do that for every single variable if i want intellisense to work?Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yeah i already have that, i showed it in my code which i sent in a sourcebin above
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
problem is that even after adding that intellisebsewasn’t working
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oh can you not see message history?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
uh is it fine if i send it later? i’m on my phone rn lol
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
cool thanks
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yeah someone else also recommended ts
just didn’t want to switch so early since i’m still learning, using the official guide and djs docs
seems like TS would be easier to use though
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oh just need to get some sort of intellisense working since i’m a beginner and it’s hard to experiment without knowing all the different methods and properties of a type 🗿
it works in index.js
just not in the execute function there
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
https://sourceb.in/tnszO60rO4
here is the code, i wrote some comments to explain teh problem.
also heres a reference to something i was told by another person in #djs-help-v14 :
https://discord.com/channels/222078108977594368/824411059443204127/1132130195332136981
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
👌
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yhh it is cuz the
console.log(inv.url);
works
it outputs a urlUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
wait so if its not a channel where an invite can be created on, the intellisense wont work?
cuz it wont recognise it
?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oh i see
so to conclude i cant get intellisense inside subdirectories unless i use jsDOC comments for each individual variable, or unless i use typescript
?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yeahh, i am pretty new to this its only been like a week so i havent memorised what everything returns
will look into that though
so that coding is easier
anyway thanks for the help
appreciate wait one more question
does that mean what i was told here https://discord.com/channels/222078108977594368/824411059443204127/1132130195332136981 is wrong?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ohh
i see
thank you
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
hmmmm
i used this if statement to narrow it down more
but the autocomplete still didnt show 🤔
ill try diff methods
or maybe just move to typescript tried both of those, but it didnt help the intellisense for
(inv.url)
it is what it is tho
ill just work without the intellisense
thanks thoUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
one sec seems like i used
inCachedGuild()
wrong
that is how you use it right?
let me try restart my VSCUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
¯\_(ツ)_/¯
oh i changed it from my previous code
apologies i should have clarified that
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oh yeah i had that code before, the
ChannelType.GuildText
then i removed it
let me try it all together
in one goUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
im assuming this is how its done
I have this now but it still shows 'any' when i hover over updating my code to this
it shows TextChannel
and now the intellisense works for inv
wow
thanks a lot
to everyone who helped
genuinely really appreciate dont want to close this thread JUST yet
alright
so theres a few more questions i have
firstly
this has fixed my problem, and autocomplete/intellisense now shows up for the
inv
variable.
- will intellisense now show up for any variable that i create, without having to specifiy the type in a jsDOC comment?
secondly
- youve shown me some code which solves my problem, but could you please explain WHY it fixes the problem
it still works even after changing some code, e.g changing @param {ChatInputCommandInteraction<'cached'>} interaction
to @param {ChatInputCommandInteraction} interaction
, or simply just deleting the if (!interaction.inCachedGuild()) return;
. im guessing i can just replace that with setDMPermission(false)
im assuming that specifying the channel type with [ChannelType.GuildText]
is the most important part
thirdly
is it simply because it narrows down the channel?
- idrk how to word this but im not sure how to implement this same code in all my different commands, but i would definitely like to use this method to enable intellisense and autocomplete in all my sub directories. if there is one general way that i can do it for any type of variable then please let me know
sorry if this seems like a lot of questions but this seems like the only place i can get help from people who can explain rather than just reading docs
ohhh i see
interesting
i might do that in the near future
thanks for all the