Doc
Doc
SIASapphire - Imagine a framework
Created by Doc on 3/17/2024 in #sapphire-support
Issue with path aliases not working when using imports (TypeScript)
Not sure what exactly is going on, normally I'm only using TS paths like "@lib/*": ["src/lib/*"] but I wanted to start implementing something similar in my bot to make it so I don't have a bunch of ../../../ and whatnot when I'm having to import certain types/classes/etc.. Never had any issues with this while using NextJS, but I assume this has to be an issue with my tsconfig/package.json files. This is the error I'm getting at the moment:
[4:56:11 AM] Starting compilation in watch mode...

[4:56:16 AM] Found 0 errors. Watching for file changes.

node:internal/modules/cjs/loader:1147
throw err;
^

Error: Cannot find module '@lib/utils'
Require stack:
- /home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/DatabaseService.js
- /home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/index.js
- /home/doc/Documents/Projects/WebDev/Robot/dist/client.js
- /home/doc/Documents/Projects/WebDev/Robot/dist/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
at Module._load (node:internal/modules/cjs/loader:985:27)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/DatabaseService.js:5:17)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/DatabaseService.js',
'/home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/index.js',
'/home/doc/Documents/Projects/WebDev/Robot/dist/client.js',
'/home/doc/Documents/Projects/WebDev/Robot/dist/index.js'
]
}
[4:56:11 AM] Starting compilation in watch mode...

[4:56:16 AM] Found 0 errors. Watching for file changes.

node:internal/modules/cjs/loader:1147
throw err;
^

Error: Cannot find module '@lib/utils'
Require stack:
- /home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/DatabaseService.js
- /home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/index.js
- /home/doc/Documents/Projects/WebDev/Robot/dist/client.js
- /home/doc/Documents/Projects/WebDev/Robot/dist/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
at Module._load (node:internal/modules/cjs/loader:985:27)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/DatabaseService.js:5:17)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/DatabaseService.js',
'/home/doc/Documents/Projects/WebDev/Robot/dist/lib/guild/user/index.js',
'/home/doc/Documents/Projects/WebDev/Robot/dist/client.js',
'/home/doc/Documents/Projects/WebDev/Robot/dist/index.js'
]
}
Currently this is my tsconfig.json:
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"compilerOptions": {
"baseUrl": ".",
"module": "CommonJS",
"moduleResolution": "Node",
"rootDir": "src",
"outDir": "dist",
"experimentalDecorators": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"tsBuildInfoFile": "dist/.tsbuildinfo",
"paths": {
"@lib/*": ["src/lib/*"]
}
},

"include": ["src"],
"compileOnSave": true
}
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"compilerOptions": {
"baseUrl": ".",
"module": "CommonJS",
"moduleResolution": "Node",
"rootDir": "src",
"outDir": "dist",
"experimentalDecorators": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"tsBuildInfoFile": "dist/.tsbuildinfo",
"paths": {
"@lib/*": ["src/lib/*"]
}
},

"include": ["src"],
"compileOnSave": true
}
If needed I can share my package.json as well. Just not sure what I'm what I'm doing wrong here... This is a real pain because I just started using eslint more to improve my code and so I'm doing a lot of refactoring and.. yeah. Considering my codebase it's a bit overwhelming. I'd like to figure out how to get these ts paths working though if possible.
13 replies
SIASapphire - Imagine a framework
Created by Doc on 12/29/2023 in #sapphire-support
Best way to use Preconditions to determine which commands show up in a /help command?
I'm looking to make a dynamic help command that'll show a user all commands available to them, but I'm really not sure how to go about checking to make sure a command is able to be run by the user before adding it to the embed. Currently the core logic for the command looks like so:
public override async messageRun(message: Message) {
const commands = this.container.stores.get('commands');
const embed = new EmbedBuilder().setTitle('Help - List of Commands').setColor('Blue').setDescription('Here are the commands you can use:');

commands.forEach((cmd) => {
// Optional: Check if the user has permission to use the command
if (cmd.enabled && !cmd.options.preconditions?.includes('OwnerOnly')) {
embed.addFields({
name: cmd.name,
value: cmd.description
});
}
});

return await message.channel.send({ embeds: [embed] });
}
public override async messageRun(message: Message) {
const commands = this.container.stores.get('commands');
const embed = new EmbedBuilder().setTitle('Help - List of Commands').setColor('Blue').setDescription('Here are the commands you can use:');

commands.forEach((cmd) => {
// Optional: Check if the user has permission to use the command
if (cmd.enabled && !cmd.options.preconditions?.includes('OwnerOnly')) {
embed.addFields({
name: cmd.name,
value: cmd.description
});
}
});

return await message.channel.send({ embeds: [embed] });
}
I'm familiar with preconditions a bit, but unsure of how sapphire's framework actually does the checking behind the scenes to see if a user passes precondition checks, I was thinking maybe that could be a way I could test each command to see if the author of the message/user of the interaction (for chatInputRun) is able to run the command. I'm also aware I'll probably have to do some further filtering rather than just getting all the commands from the stores (since I believe there will be duplicate entries for commands that have messageRun/chatInputRun/contextMenuRun methods) but right now I'm focused on just figuring out a good way of figuring out whether or not to include a command based on the user using the help command first. Any ideas?
5 replies
SIASapphire - Imagine a framework
Created by Doc on 11/28/2023 in #sapphire-support
Is there a way to use Sapphire to reset previously registered slash commands?
So, I've got a bot I'm working on that uses Sapphire and recently, just as an example, I generated a unban.ts slash command while I had npm run:watch running (so it registered the command with the bot). I then moved the unban.ts file to the Moderation folder I created for commands like this one, and now I need the previous unban command to become unregistered. Is there any way I could have Sapphire automatically unregister slash commands created like this one upon finding that the files for the commands no longer exist? Or am I gonna have to do it the old fashioned way using discord.js?
23 replies