Problem with extended SapphireClient

Hi there I'm trying to extend the SapphireClient to add some custom property. Here's all what I got already:
import { SapphireClient } from "@sapphire/framework";
import { container } from "@sapphire/pieces";
import type { ClientOptions } from "discord.js";
import { drizzle } from "drizzle-orm/node-postgres";
import pg from "pg";
import { dbConnectionString } from "../config.js";

const { Client } = pg;

// @ts-expect-error Somehow errored with d.js ClientOptions conflict
export class BotClient extends SapphireClient {
public readonly db = drizzle(new Client({
connectionString: dbConnectionString
}));

public constructor(public readonly options: ClientOptions) {
super(options);

Object.assign(container, { db: this.db });
}
}

declare module "@sapphire/framework" {
type SapphireClient = {
readonly db: BotClient["db"];
};
}

declare module "@sapphire/pieces" {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Container {
readonly db: BotClient["db"];
}
}
import { SapphireClient } from "@sapphire/framework";
import { container } from "@sapphire/pieces";
import type { ClientOptions } from "discord.js";
import { drizzle } from "drizzle-orm/node-postgres";
import pg from "pg";
import { dbConnectionString } from "../config.js";

const { Client } = pg;

// @ts-expect-error Somehow errored with d.js ClientOptions conflict
export class BotClient extends SapphireClient {
public readonly db = drizzle(new Client({
connectionString: dbConnectionString
}));

public constructor(public readonly options: ClientOptions) {
super(options);

Object.assign(container, { db: this.db });
}
}

declare module "@sapphire/framework" {
type SapphireClient = {
readonly db: BotClient["db"];
};
}

declare module "@sapphire/pieces" {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Container {
readonly db: BotClient["db"];
}
}
How I initialize the client:
const client = new BotClient({
baseUserDirectory: "./",
intents: ["Guilds"]

});

client.on("ready", () => {
console.log(`Logged in as ${client.user?.tag}!`);
});

await client.login();
const client = new BotClient({
baseUserDirectory: "./",
intents: ["Guilds"]

});

client.on("ready", () => {
console.log(`Logged in as ${client.user?.tag}!`);
});

await client.login();
But then somehow discord.js throws this error:
D:\[redacted\node_modules\.pnpm\[email protected]\node_modules\discord.js\src\client\websocket\WebSocketManager.js:147
largeThreshold: ws.large_threshold,
^

TypeError: Cannot read properties of undefined (reading 'large_threshold')
at WebSocketManager.connect (D:\[redacted]\node_modules\.pnpm\[email protected]\node_modules\discord.js\src\client\websocket\WebSocketManager.js:147:28)
D:\[redacted\node_modules\.pnpm\[email protected]\node_modules\discord.js\src\client\websocket\WebSocketManager.js:147
largeThreshold: ws.large_threshold,
^

TypeError: Cannot read properties of undefined (reading 'large_threshold')
at WebSocketManager.connect (D:\[redacted]\node_modules\.pnpm\[email protected]\node_modules\discord.js\src\client\websocket\WebSocketManager.js:147:28)
any idea what is really happening here?
Solution:
Welp fixed, it seems that the options were overrided by the public keyword
Jump to solution
2 Replies
yuki
yukiOP7mo ago
When I try initialize the client with original SapphireClient, it worked just fine Btw here's the types conflict error that i supressed Seems that the discord.js's default options were gone that is logged from discord.js node_modules btw
Solution
yuki
yuki7mo ago
Welp fixed, it seems that the options were overrided by the public keyword
Want results from more Discord servers?
Add your server