Sapphire - Imagine a framework

SIA

Sapphire - Imagine a framework

Welcome to the Sapphire Discord server! The next-gen object-oriented Discord.js bot framework can be found here.

Join

sapphire-support

discordjs-support

old-sapphire-support

old-discordjs-support

old-application-commands-and-interactions

Scheduled Task Does Not Remove on Fail

I have a listener that creates a new task when a member joins voice if a condition is met, and removes it when they leave. The task itself executes perfectly fine, however, if it errors it will not remove the task. I do handle users leaving the channel in the voice state code, however if the bot has downtime and the member leaves during it, it'll have to error out. I'm not entirely sure if this is intended behavior and I'm just understand the use-case wrong, I checked documentation for bull and it seems like it should remove on error, but it does not....
Solution:
Well the plugin is just a fairly tiny wrapper around the bullmq library and that is a bullmq option. So it only counts when it fails on the bullmq side. This could be when it fails to send from redis to the client for example.

Precondition not running

I've taken this from a working template project of mine, but I can't for the life of me figure out where this message is coming from.. it works in the template project, and checking the docs I can't see what I'm missing... I'm missing something stupid right? It's sitting in a preconditions folder, just the same The log message is not my own. 2024-11-02 22:59:01 - [WARN] preconditionUnavailable - The precondition "OwnerOnly" is not available. ...
Solution:
```ts declare module "@sapphire/framework" { interface Preconditions { OwnerOnly: never; }...

Dilemma 😫

I’m debating whether to handle audit events in a single file or break each event out into separate modules, aligning with the Sapphire Framework’s philosophy. I prefer to keep my code compact, even though I know it won’t significantly impact the end result, it’s just something I always spend extra time on for my own satisfaction. Now, my main question is whether opting for a single file will compromise performance compared to the modular approach that Sapphire advocates.

cant declare container items

cannot declare prisma as a child of container
No description

Paginated Message actions issue

I’m working with a PaginatedMessage in my command, where I display entities and use a dropdown (select menu) for users to choose an entity from the current page to view its details. However, if there are fewer than 10 entities, the dropdown doesn’t respond when selecting an entity, as if the command isn’t recognized as a PaginatedMessage. I suspect this may be because only one page is created, so the actions aren’t registered. I saw the setPageActions() method in the docs, could it help here? I've included screenshots: one with fewer than 10 entities (not considered as a Paginated message) and one with more (Paginated message). Thank you for your help !...
No description

Space separated arguments

Hello, I've created a custom messagePreParse that allows spaces as separators and it ended up parsing options and flags way faster than default while still providing me the info I needed.
After testing and finally feeling comfortable with it, I continued exploring Sapphire and added the subcommands package, quickly realizing they weren't compatible, as Subcommand's PreParseReturn only accepts types that extend from Args and mine would return a different (simpler) kind of object. So I've been dealing with this for a few days and I'm trying to figure out what would be the optimal approach as Lexure doesn't support spaces as a separator for options (I think?)....

New component under a PaginatedMessage

Hello ! I want to add a new component under my PagniatedMessage. This PaginatedMessage is a list embed that represents entities of a model. The user is invited to chose a row to edit via a select menu under the embed. The select menu is successfully added when the embed shows but disapear when I change page. I would like to know how to make my dropdown list refresh on every page change, is there a listener or something like that that can handle this? Here is the code of the listEntities method : ```javascript protected async listEntities(interaction: CommandInteraction<CacheType>, page: number) {...
Solution:
I think you want to use actions
No description

Logger - log to txt file

I am trying to use this to clone console.log logs to a txt file. Any way I can do the same for the sapphire logger as well? Thanks. ```ts import * as fs from "fs"; ...

How can I delay the loading of pieces?

Is there a way I can control when the pieces are loaded instead of having them loaded automatically on <SapphireClient>.login? I'd like to login to the client, then wait for the resolving of an async function, and then load the pieces in.
Solution:
mark them as internal by prefixing the file name with _ or putting them in a directory that doesn't get automatically detected by Sapphire (i.e. a folder other than arguments, commands, etc) then use ```ts import { container } from '@sapphire/framework'; container.stores.loadPiece({ name: 'name of the piece here',...

Seeking Guidance on Custom Discord Bot for Voting System

Hey everyone! I'm a beginner looking to dive into the world of Discord bots and would love your help. My goal is to create a customized bot for our small server that enhances our community experience. Whether you're an expert or just starting out, any tips, resources, or guidance would be greatly appreciated I have already customized my bot, and I want it to help me manage a small community server. Suppose, I have 500 people in my community, and I expect around 200 of them to participate in an event called voting. Discord will be used to verify who voted and who did not. To do that, I will create a thread where all participants who want to join will be listed. Each participant must receive 199 votes by the end of the game. To prevent fraud, I will randomly add names of non-participants to the list. If anyone reacts to those names, they will face penalties...

Subcommand in Direct Messages even with guildIds option

I have { guildIds: [this.container.config.guildId] } in my subcommand registry, but I still can see command in direct messages with that bot
No description

[ERROR] Encountered error on event listener "CorePreChatInputCommandRun"

I'm getting this error repeatedly on an OwnerOnly precondition: ``` [ERROR] Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js" TypeError: Cannot read properties of undefined (reading 'isErr') at Object.chatInputSequential (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/utils/preconditions/conditions/PreconditionConditionAnd.js:22:18)...
Solution:
you need to return this.error

commands arent working

someone help me, the bot isnt working, it does go online, I dont get any error. ping.ts: ```ts...
Solution:
top of the guide:
No description

registerContextMenuCommand type error

I recently updated all of my packages and I expected some errors to popup and I've managed to fix most of them except this one: Argument of type 'ApplicationCommandType.User' is not assignable to parameter of type 'ContextMenuCommandType'. This error appears on this line: ```ts registry.registerContextMenuCommand(builder => builder.setName('Rob').setType(ApplicationCommandType.User));...
Solution:
This is a known bug of the latest discord.js version To bypass it for the time being, you can either downgrade, or do a little typing trickery like ApplicationCommandType.User as ContextMenuCommandType...
No description

Preconditioning a whole category of commands

Is it possible to apply certain preconditions to a category of commands? if so.. how?

PaginatedMessage actions on a single page

Hi!, I'm currently using the super convenient PaginatedMessage class and calling the .addPageActions() method to add actions with a run() callback to each page. This has been working great, I have however noticed that the run() function is only being called when the total number of pages is more than 1. I checked out the code setting up the collector for the message, and that indeed seems to be the case. I was wondering if there was a way to ensure that custom actions are called in the specific case where the number of pages is exactly 1 while still being able to access the passed context....
Solution:
You'll have to extend the class and overwrite the appropriate method. Our believe is that there is no point to showing a paginated message with page controls when there is only 1 page and in such a case you should write your code so that the embeds / content / component are sent directly. This is to discourage the misuse of the class and potential over engineering....

Sapphire Dynamic Cooldown Per User

Hi! i was wondering if sapphire can use a dynamic cooldown, so i can set a dynamic cooldown per user. Does it possible? let me know. Thanks!

Bun hot module reloading & starting in production with Sapphire

Hey, was curious what special work would need to be done to get HMR working with Bun Was looking at https://github.com/sapphiredev/bun-example/blob/main/package.json and that example doesn't include HMR My understanding of the plugin https://www.npmjs.com/package/@sapphire/plugin-hmr is that it was watching for changes in the outputed files, and since bun just runs the code directly I assume it's incompatible, but figured I'd check...
Solution:
You can use the plugin regardless. It scans the files as they are in the store and with Bun that's TS files. That said, if it doesn't work that might be up to Chokidar, or Bun's compatibility with it. And yes you can still use NODE_ENV with Bun. But if you're so inclined you can also use BUN_ENV. It's arbitrary....

addStringOption applyLocalizedBuilder

Hey, Is it possible to use localizedBuilder on the choices for addStringOption? ```ts...