Skip to content

Commit

Permalink
fix: Client constructor using handlers being they have been initial…
Browse files Browse the repository at this point in the history
…ised (#72)

* fix: `Client` constructor trying to use handlers being they have been initialised

* chore: add changeset
  • Loading branch information
apteryxxyz authored Sep 10, 2024
1 parent 8c121f4 commit 558b73c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-carrots-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@buape/carbon": patch
---

fix: `Client` constructor trying to use handlers being they have been initialised
30 changes: 16 additions & 14 deletions packages/carbon/src/classes/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,32 @@ export class Client {
if (!options.clientId) throw new Error("Missing client ID")
if (!options.publicKey) throw new Error("Missing public key")
if (!options.token) throw new Error("Missing token")

this.options = options
this.commands = commands
if (this.options.autoRegister) {
this.commands.map((command) => {
command.components.map((component) => {
this.componentHandler.registerComponent(new component())
})
command.modals.map((modal) => {
this.modalHandler.registerModal(new modal())
})
})
}

this.commandHandler = new CommandHandler(this)
this.componentHandler = new ComponentHandler(this)
this.modalHandler = new ModalHandler(this)

const routerData =
this.options.mode === ClientMode.Bun && this.options.port
? { port: this.options.port }
: {}
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
this.router = AutoRouter<IRequestStrict, any[], Response>(routerData)
this.rest = new RequestClient(options.token, options.requestOptions)
this.componentHandler = new ComponentHandler(this)
this.commandHandler = new CommandHandler(this)
this.modalHandler = new ModalHandler(this)
this.setupRoutes()

if (this.options.autoRegister) {
for (const command of commands) {
for (const component of command.components)
this.componentHandler.registerComponent(new component())
for (const modal of command.modals)
this.modalHandler.registerModal(new modal())
}
}
if (this.options.autoDeploy) this.deployCommands()
this.setupRoutes()
}

/**
Expand Down

0 comments on commit 558b73c

Please sign in to comment.