#Custom Store not working

1 messages · Page 1 of 1 (latest)

somber nymph
#

Hey guys,

I tried myself on writing a custom store

import { Piece, Store } from '@sapphire/framework';

export class InfrastructureDiscordServiceStore extends Store<Piece, 'infrastructure-discord-services'> {
    public constructor() {
        super(Piece, { name: 'infrastructure-discord-services' });
    }
}

I try to register it in my client with this code piece

const root = getRootData().root;
this.stores.register(new InfrastructureDiscordServiceStore()).registerPath(join(root, 'infrastructure', 'discord', 'service'));

Log output:

2025-05-26 10:39:14 - INFO  - └─ Loaded 0   infrastructure-discord-services.

Path should be correct. But at the end no store will be registered. My stores are all built like this

export class RoleService extends Piece {
    public constructor(context: Piece.LoaderContext, options: Piece.Options) {
        super(context, { ...options, name: 'role-service' });
    }
}

In the end it's not working. Funny thing is that when I try to register the store manually with

void this.stores.loadPiece({
            store: 'infrastructure-discord-services',
            name: 'role-service',
            piece: RoleService
        });

the Service is registered in the store.
Log output:

2025-05-26 10:39:14 - INFO  - └─ Loaded 6   infrastructure-discord-services.

What am I doing wrong?
I am thankful for all help 🥲

distant hearthBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

fickle zealot
#

have you tried mimicking how stores are registered for plugins?

#

specifically plugins dont do this.stores.register(new InfrastructureDiscordServiceStore()) but this.stores.register(this.server.routes) and assign this.server beforehand. They also dont do registerPath which is implied to be join(getRootData().root, nameOfTheStore)

somber nymph
fickle zealot
somber nymph
#

Can I use hooks like as the plugins use? As for some services I need a logged in Bot for example.

2nd question:
Can I still do the .registerPath() method somewhere in the files then? My pieces do not live in the path join(getRootData().root, nameOfTheStore) as I'm using some other folder structure

fickle zealot
#

yes and yes

somber nymph
#

Alright. I tried to copy and edit the most of the utilities plugin.

This is my store register call

public static [preInitialization](this: SapphireClient): void {
        this.discordServices = new DiscordServices();
        this.stores.register(this.discordServices.store).registerPath(join(getRootData().root, 'infrastructure', 'discord', 'service'));
    }
import { Store } from '@sapphire/framework';
import { DiscordService } from './DiscordService';
import { join } from 'path';
import { getRootData } from '@sapphire/pieces';

export class InfrastructureDiscordServiceStore extends Store<DiscordService, 'discordServices'> {
    public constructor() {
        super(DiscordService, { name: 'discordServices', paths: [join(getRootData().root, 'infrastructure', 'discord', 'service')] });
    }
}

Now there are 2 paths set. First the
discord-bot\dist\infrastructure\discord\serviceand discord-bot\dist\discordServices. I tried to set paths in the Store itself. How can I prevent the 2nd store path prevent beeing registered?

fickle zealot
#

uhm not sure tbh

#

but it doesnt really matter

#

just dont create the direct ory and dont put files in it

#

take for example sapphire Args. If I dont have Args that doesnt mean that the Argument store doesnt have the path registered. It's just sitting there doing nothing.

somber nymph
#

Alright, then this will do the trick. It's working by now. Thanks for the help PES_CowboyLove