Prisma with Sapphire

Hello, im new to sapphire framework.. but i have question why it does not work?
import "dotenv/config";
import { container, SapphireClient } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";
import prisma from "./lib/prisma";

declare module "@sapphire/pieces" {
interface Container {
dtb: typeof prisma;
}
}

export class BotClient extends SapphireClient {
public constructor() {
super({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
}

public override async login(token?: string): Promise<string> {
console.log("Connecting to database...");
container.dtb = prisma;
console.log("Database connected.");
return super.login(token);
}

public override destroy() {
container.dtb.$disconnect();
return super.destroy();
}
}
import "dotenv/config";
import { container, SapphireClient } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";
import prisma from "./lib/prisma";

declare module "@sapphire/pieces" {
interface Container {
dtb: typeof prisma;
}
}

export class BotClient extends SapphireClient {
public constructor() {
super({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
}

public override async login(token?: string): Promise<string> {
console.log("Connecting to database...");
container.dtb = prisma;
console.log("Database connected.");
return super.login(token);
}

public override destroy() {
container.dtb.$disconnect();
return super.destroy();
}
}
The bot dont start at all or even the prints doesnt get printed.. why ?
2 Replies
Solution
Favna
Favna17h ago
Well from starters you don't need to extend the client and override login like you do https://github.com/favware/xiveventbuddy/blob/main/src/lib/setup/prisma.ts https://github.com/favware/xiveventbuddy/blob/main/src/lib/setup/all.ts https://github.com/favware/xiveventbuddy/blob/main/src/xiveventbuddy.ts you also dont need to call disconnect. That's why it's $disconnect, it's meant for internal use. The process exists on destroy so the database connection will get cleaned automatically. Outside of that though I'm not entirely sure but I think it might be related to that you're not spreading parameters in the constructor to the super call.
bux1k
bux1kOP14h ago
Okay I'll try it like this.

Did you find this page helpful?