#Stuck on discord.js guide while using TypeScript

24 messages · Page 1 of 1 (latest)

urban dragon
#

• 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.

oak chasm
#

my .commands property is not being recognized with typescript.

#

I'm not not sure how to do the part in the discord.js guide that I've highlighted in the first screenshot.

unborn laurelBOT
#

Tag suggestion for @oak chasm:
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 type

oak chasm
edgy star
#

It links to a guide on augmenting

#

It would look something like this

oak chasm
#

I have trouble understanding the guide when I look at it. It's a little hard for me to visualize in my head on how to implement it.

edgy star
#
declare module "discord.js" {
  export interface Client {
    commands: Collection<string, Command>;
  }
}```
#

Replace Command with your own command type

oak chasm
#

Is this suppose to be added at the top of my index.ts?

#

err no, it would go in a d.ts file it seems.

oak chasm
edgy star
#

The type of the object you're storing in client.commands

#

Whatever it might be

oak chasm
#

It's a Collection object right?
I'm just trying to follow through with the discord.js guide

edgy star
#

Yeah but what are you putting in the collection

oak chasm
edgy star
#

Thats what that type is for

#

How familiar are you with TypeScript?

oak chasm
#

Not very familiar. I've only set it up a couple times, but this is the first time I'm trying to set it up on a discord js bot.

edgy star
#

The guide really barely touches on TypeScript, its written with JS examples throughout

oak chasm
#

I see