Will the custom path in a store apply also when using cogs (or modules)?

If I have the following code that changes the stores path:
this.stores.get('arguments').registerPath(join(this.rootData.root, 'options'));
this.stores.get('interaction-handlers').registerPath(join(this.rootData.root, 'interactions'));
this.stores.get('arguments').registerPath(join(this.rootData.root, 'options'));
this.stores.get('interaction-handlers').registerPath(join(this.rootData.root, 'interactions'));
And I also use a cog system that is grouped in a single folder:
this.stores.registerPath(join(this.rootData.root, 'cogs', 'audio'));
this.stores.registerPath(join(this.rootData.root, 'cogs', 'moderation'));
this.stores.registerPath(join(this.rootData.root, 'cogs', 'music'));
this.stores.registerPath(join(this.rootData.root, 'cogs', 'audio'));
this.stores.registerPath(join(this.rootData.root, 'cogs', 'moderation'));
this.stores.registerPath(join(this.rootData.root, 'cogs', 'music'));
Would sapphire, instead of looking for "interaction-handlers" inside each cog, would look instead for the custom path folder name, which would be "interactions"? Same thing with "arguments" being "options"? If not, how would I accomplish this? Or is there a better way of doing this?
Solution:
missing some path elements there arent ya
Jump to solution
37 Replies
Sandy Stone
Sandy StoneOP•4mo ago
@Favna Yeah, that's exactly what I'm doing I'm asking if Sapphire will know the new folder names, like I explained in the last paragraph in here
Favna
Favna•4mo ago
I think it should work yes, but the rule of thumb is https://tryitands.ee
Sandy Stone
Sandy StoneOP•4mo ago
Nope, it doesn't works It doesn't register the commands, says there were 0 commands registered
Sandy Stone
Sandy StoneOP•4mo ago
No description
Sandy Stone
Sandy StoneOP•4mo ago
Moving the interactions or options folder outside to the src folder does work though So, it seems customizing the store's name doesn't works for cogs? How would I get them working?
vladdy
vladdy•4mo ago
your code looks correct, just make sure the root directory points to the same directory as your main entry in pkg.json so if your main is dist/index.js for example, your rootpath should start at dist
Sandy Stone
Sandy StoneOP•4mo ago
Yup, it is, yet it doesn't works 😭
vladdy
vladdy•4mo ago
huh, fascinating can you set Store.logger to console.log or something and check what it prints (expect spam)
Sandy Stone
Sandy StoneOP•4mo ago
Alright, let me try
vladdy
vladdy•4mo ago
do that before calling login btw
Sandy Stone
Sandy StoneOP•4mo ago
💀
No description
Sandy Stone
Sandy StoneOP•4mo ago
this is what i did
No description
vladdy
vladdy•4mo ago
i said set not log :CLk_Kekega: Store.logger = console.log
Sandy Stone
Sandy StoneOP•4mo ago
oh 😭
Sandy Stone
Sandy StoneOP•4mo ago
Sandy Stone
Sandy StoneOP•4mo ago
this is my custom client, might be helpful
import { ApplicationCommandRegistries, RegisterBehavior, SapphireClient } from "@sapphire/framework";
import { container, getRootData } from "@sapphire/pieces";
import path from "path";
import { Settings } from "./settings";

export class Client extends SapphireClient {
private _isInitialized = false;
private _rootData = getRootData();

constructor() {
super({
intents: [],
baseUserDirectory: null,
});

this._init();
}

private _registerModule(name: string) {
this.stores.registerPath(path.join(this._rootData.root, "modules", name));
}

private _init() {
container.settings = new Settings();

this.stores.get("commands").registerPath(path.join(this._rootData.root, "cmds"));

this._registerModule("base");

ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(RegisterBehavior.BulkOverwrite);
ApplicationCommandRegistries.setDefaultGuildIds([container.settings.environment.discord.development.guildId]);

this._isInitialized = true;
}

get isInitialized() {
return this._isInitialized;
}
}

declare module "@sapphire/pieces" {
interface Container {
settings: Settings;
}
}
import { ApplicationCommandRegistries, RegisterBehavior, SapphireClient } from "@sapphire/framework";
import { container, getRootData } from "@sapphire/pieces";
import path from "path";
import { Settings } from "./settings";

export class Client extends SapphireClient {
private _isInitialized = false;
private _rootData = getRootData();

constructor() {
super({
intents: [],
baseUserDirectory: null,
});

this._init();
}

private _registerModule(name: string) {
this.stores.registerPath(path.join(this._rootData.root, "modules", name));
}

private _init() {
container.settings = new Settings();

this.stores.get("commands").registerPath(path.join(this._rootData.root, "cmds"));

this._registerModule("base");

ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(RegisterBehavior.BulkOverwrite);
ApplicationCommandRegistries.setDefaultGuildIds([container.settings.environment.discord.development.guildId]);

this._isInitialized = true;
}

get isInitialized() {
return this._isInitialized;
}
}

declare module "@sapphire/pieces" {
interface Container {
settings: Settings;
}
}
vladdy
vladdy•4mo ago
and is the base correct? bc its saying /src and you're in TS land, so unless you're using bun/ts-node/tsx with main: src/entrypoint.ts or w/e in your pkg.json, that will never work
Sandy Stone
Sandy StoneOP•4mo ago
yup im using bun
vladdy
vladdy•4mo ago
interesting do those paths look correct?
Sandy Stone
Sandy StoneOP•4mo ago
this is the directory
No description
Sandy Stone
Sandy StoneOP•4mo ago
should work according to the paths in the custom client, specified here
vladdy
vladdy•4mo ago
well your cmds will never load bc the paths are wrong
Sandy Stone
Sandy StoneOP•4mo ago
wat
vladdy
vladdy•4mo ago
this.stores.get("commands").registerPath(path.join(this._rootData.root, "cmds"));
Solution
vladdy
vladdy•4mo ago
missing some path elements there arent ya
vladdy
vladdy•4mo ago
modules/base
Sandy Stone
Sandy StoneOP•4mo ago
yeah that's what i thought, and it's what i meant in the thread description 😭 here
vladdy
vladdy•4mo ago
if you use registerPath on a store you need to give the full path to the folder your _registerModule will always work because you tell ALL stores to go to that path and check for their folder if you want to use a custom folder name.. you'll need to register it for its specific store, full path and all
Sandy Stone
Sandy StoneOP•4mo ago
so it'd have to be like this this.stores.get("commands").registerPath(path.join(this._rootData.root, "modules", "base", "cmds")); ??
vladdy
vladdy•4mo ago
si or rename the cmds folder to commands :mmLol:
Sandy Stone
Sandy StoneOP•4mo ago
oh ok so i can't set custom paths or folder names for each store when doing this.stores.registerPath(join(this.rootData.root, 'cogs', 'audio')); basically, because sapphire would bind to the default namings which would be for example ìnteractions-handler
vladdy
vladdy•4mo ago
mhm that said you can probably optimize this by scanning the dir yourself and doing the mapping but yeah, that be how it be
Sandy Stone
Sandy StoneOP•4mo ago
okok, would this be a bad approach for what i want to accomplish? are there better ways or this is already enough? yup that's what i was going to do
vladdy
vladdy•4mo ago
nop, that works too of course you can always move away from fs registering to virtual pieces, and then it doesnt matter anymore but idk if we have docs for that yet
Sandy Stone
Sandy StoneOP•4mo ago
okok, that's it for now, tysm 🫶
vladdy
vladdy•4mo ago
Want results from more Discord servers?
Add your server