Access extended sapphire client

Following usecase: I extended the sapphire client in order to create custom collections etc. Is there any way I can access the extended client through the container?
Solution:
container.client, and you need to add module augmentation to add the properties to the Client class from discord.js ```ts declare module 'discord.js' { interface Client { myCustomProperty: any...
Jump to solution
9 Replies
Solution
Favna
Favna•16mo ago
container.client, and you need to add module augmentation to add the properties to the Client class from discord.js
declare module 'discord.js' {
interface Client {
myCustomProperty: any
}
}
declare module 'discord.js' {
interface Client {
myCustomProperty: any
}
}
Favna
Favna•16mo ago
anyway why would you add them to the client specifically when you can also just add them to the container directly. Save yourself the trouble of doing container.client.custom and just do container.custom
kyra
kyra•16mo ago
By the way, you're more encouraged to extend container rather than SapphireClient 👀
Favna
Favna•16mo ago
It's also far easier because you can just:
import { container } from '@sapphire/framework';
import { CustomColelction } from 'whatever';

container.custom = new CustomCollection();

declare module '@sapphire/framework' {
export interface Container {
custom: CustomCollection;
}
}
import { container } from '@sapphire/framework';
import { CustomColelction } from 'whatever';

container.custom = new CustomCollection();

declare module '@sapphire/framework' {
export interface Container {
custom: CustomCollection;
}
}
ShowCast
ShowCast•16mo ago
Thanks for the help <:PES_Ok:493353112501747712>
~
~•16mo ago
i tried this and it's giving me an error
~
~•16mo ago
KaydaFox
KaydaFox•16mo ago
for typescript to recognise it for me, i have to do it like this
declare module '@sapphire/pieces' {
interface Container {
config: KaydaConfig
db: PrismaClient;
}
}
declare module '@sapphire/pieces' {
interface Container {
config: KaydaConfig
db: PrismaClient;
}
}
seems to be done that way in iriss too so @Upsided i think you should maybe try that instead?
~
~•16mo ago
thanks mayne it worked