hopefully two simple questions
1. how do I check my djs version? i just installed it and idk how to check
2. how can i use djs with typescript? i keep getting type errors cuz idk what to annotate stuff with
im also very new, its awesome to be here 🙏
52 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!oh
v14.15.2
1. npm ls discord.js
2. pretty sure the guide has some information in regards to typescript usage
do you know where in the guide i can find that usage?
depends, what errors are you encountering
just missing type annotations
the same that you would get if you did this
can't compile TypeScript:
a
has an implicit any
annotation
etcYeah, you gonna have to add the required annotations yourself, thats part of typescript
you can find all types in the documentation though
ok thank you ❤️
should i use ts or just use js?
ts
ok
so just change the file extension?
this shit is confusing
i changed it to
.cjs
then it told me to change it to .mjs
then fs
cant be imported from node:fs
2 things:
1. what do i do then? im going off the docs as a basic guide
2. what does "destructure" mean in javascript terms?:mdn: Destructuring assignment
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
ah i see
what do i do then? im going off the docs as a basic guideEither import everything from the module and name that variable fs, as usual, or just import the individual functions
hm ok i see
confused why this wont let me assign the collection instance to the commands attribute like it says in the docs 🤷
just create const commands = new Collection()
alr thank you 👍
getting this now
apologies if im bothering you btw i dont mean to
what are u doing xD
wait lemme get on my laptop
tihis is my whole code
Why are you using client.commands if you declared commands as a variable
🤷
im just reading the docs
this page
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
when i ran everything in js, it worked perfectly fine, but after switching to ts, everything fell apart
Then keep using js, you have to understand how typescript works first if you're gonna switch
The whole point of typescript is it's type system, the reason you cannot use client.commands is because Client doesn't have a commands property, you have to declare it or extend the class
ah ok i see now
using typescript is basically easy
wdym?
wait
This is my command handler
the only thing different to js is this
why use ts if you're just going to
any
:Thonk:this is stuff for commands
so type them accordingly
when i export my command with data as SlashCommandBuilder and async execute as a function what type is it?
you make a type
why should i
.
i use any only in these variables
:meguFace:
any is the flextape of ts 😭
>have an issue
>dont know why
>"incorrect type"
>replace it with
any
>works perfectlyif that doesnt work you do the magical
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Or use module augmentation
Which is what I personally recommend
We highly recommend you extend the
Client
structure properly instead of just attaching custom properties like .commands
to the regular discord.js Client
instance.
- Using typescript, you might want to consider casting or augmenting the module typeUnknown User•6mo ago
Message Not Public
Sign In & Join Server To View
i would beg to differ, “as unknown as” is on the same level as “any”, as with either one you should be switching back to js
only difference is the “as unknown as” is a suggestion
🤷♂️
oh trust me i know, theyre the exception only because i dont wanna lose access to vscode 😭
and possibly keep my life
yes
im hypocritical because i also use “as unknown as”
no i should suggestedly switch back to js, thats my logic
an action row builder
:ch_hehe:
But you don't have to do it like this lmao
In TypeScript the
ActionRowBuilder
class has a generic type parameter that specifies the type of component the action row holds:
see but i learned that the more lines the better your code is
so this is against my morals
gosh you might be right hmmm
shouldve made a new variable to declare it as unknown as instead
smh myself
but there i cant make custom typings, or use cool commented out typings at all!!
but then my files would look like normie orange
:ch_nananono:
so much extra work… though
this is the guide i follow
the only true guide btw
all the other ones spread lies