Sapphire - Imagine a Framework

SIA

Sapphire - Imagine a Framework

Sapphire is a next-gen object-oriented Discord.js bot framework.

Join

sapphire-support

discordjs-support

old-sapphire-support

old-discordjs-support

old-application-commands-and-interactions

Slash Commands

Hey, has anyone experienced issues with slash commands randomly deregistering? This has been happening to me every week or so. There are no errors in the logs, so I’m confused as to what exactly is going on.

Multiple Button Handlers, only 1 takes in a request

currently, I have 2 seperate files that both have button handlers. However, when a button is pressed, it only does parsing in 1 of the files. Both are in the interaction-handlers directory. src/interaction-handlers/operation.ts ```ts import {...

Add Choices To An Already Registered Command

Is there any way to add choices to an already registered command? For example, say I have a command that allows a user to add a fruit to a list. Then I have another command that allows the user to take the fruit off the list. I want to be able to update the choices in the command every time the user adds or removes a fruit. Is this possible with Sapphire?...

Creating a button handler

Hey! I would like to know if there is a way to create a button handler using Sapphire. I would like to read all files from a folder called "buttons" and store the data inside my container. I'd then check if there is an existing button with the given interaction id inside my container and if there is, I'd run the execute function. I came up with some code but can't manage to get it working. I'll attach it down below. Thanks in advance for all the help šŸ™‚...

New to Sapphire! Where should I start?

Hey! I've been developing Discord bots with discord.js for over two years now and I've recently made the jump to Sapphire and TypeScript. Where should I start? I am reading the guide to get an idea of how the framework works but I'd really appreciate any tips or guidance on what my next steps should be. Thank you very much in advance 🫶

sending html using api plugin

Hi, is it possible to send content with the mimetype text/html using the api plugin? I would like to expose a small landing page for an external oauth flow....
Solution:
``ts response // @ts-expect-error This should be Mimetypes enum but it currently doesn't have text/html` .setContentType('text/html') .status(HttpCodes.OK)...

Validate arguments without triggering cooldown

Is there any way for me to validate arguments received in a text command without having the cooldown for that command triggered? Is there a method I can call to stop the code of that command (right now I am just throwing a custom error when the arguments are problematic) without the cooldown running all over again? Thanks!

Set precondition's name instead of having it resolve from file name

Is it possible to set a precondition's name manually instead of having it resolve from file name, similar to how it can be done with listeners, commands and interaction handlers?

Should I create multiple interaction handlers for each interaction type?

If I'm understanding correctly the point of the parse method is to determine whether a specific interaction handler should run, so that means we can create multiple handlers of the same type (Button for example) right? The guide does mention this is possible for listeners but doesn't say anything about it for interaction handlers so I just wanted to confirm, thanks!...
Solution:
Yeah, you probably don't want the code to handle every type of button in the same handler. For instance, I have one handler that deals with buttons on polls, a separate handler that deals with confirm/deny buttons, and another one that just deals with dismissing & disabling message components.

Passing down arguments of Commands to the Interaction Handlers

I have a command that takes a user argument like /clan member @MindLabor and this command creates a message with Buttons. I also have a button interaction handler which runs when the button is clicked. But in that interaction handler I cannot find the arguments of my original command that created the message. Is there a good way of "passing" the data from where the buttons are built to the handler? Button Message Creation: ```ts return interaction.reply({...
Solution:
That way, my button handler can check if the label starts with the unique-label, then I can checke if the user who clicked the button matches the user who requested the button, and finally I get whatever other information I need to actually preform the action (in your case that looks like it owuld be another userID)

Node Heap Allocation Issue

I don't know why this keeps happening but sometimes when I try to build I get an out of memory issue. I tried giving node 16gb but it just took all of it and threw out of memory again. So I assume this is a memory leak when I run tsc. I dont know why somtimes it worked and other times not but now its not working anymore and I have no clue why or how to fix it. ChatGPT just says well give it more memory. Has anybody an idea? Here is my package.json and tsconfig: (I never had this before and my ts...
Solution:
cant really follow on the discussion there but fixed it for now using pnpm update. I guess some lib was outdated with that bug

Triggering a Modal, Message With Buttons, ...

I want to make a command that sends a message with buttons and when a button is clicked it gives a popup with something like "Are you sure that you want to delete X?". Now I looked at the guide but it only says how to handle these interactions. But how can I trigger them in the first place? https://www.sapphirejs.dev/docs/Guide/interaction-handlers/modals...

Passing down from the index.ts and arguments to subcommands

I have two Issues: 1. I want to use Firestore which I'm initilizing in the index.ts but I dont know how to access variables from the index.ts in my command folders. 2. How do I access arguments for subcommands? ...
Solution:
As for firestore, you can either put it into client's container store Or initialise firestore in seperate file, export the firestore object/database. Then import it where you need...

Cog Actions

So, my bot is running the cog-like system. However, I was wondering if there was a way to run actions on the entire cog. For example: Unloading the cog Loading the cog ...
Solution:
first of all I will assume you followed https://www.sapphirejs.dev/docs/Guide/additional-information/implenenting-a-discordpy-like-cog-system If you did then just like how you call register you can also call deregisgter https://www.sapphirejs.dev/docs/Documentation/api-pieces/classes/StoreRegistry#deregister Alternatively you can loop through all the stores held in the particular StoreRegistry (cog) and call store.unloadAll()...

Is there anyway using Subcommand plugin with Slash command

Seem like chatInputRun is not exist on SubCommand

Reload Command

I'm having trouble making a reload command, I've tried so many things... I'm using CommandStore to do this (load and unload modules) If anybody could provide an example of how to do this, that would be amazing ...

Vebose Child Folder not register slash command

room-member.js will not trigger registerApplicationCommands

Happen Issue when try to watch:start with examples

I meet this issue when trying to clone example and watch:start

Type '"Rules"' is not assignable to type 'PreconditionEntryResolvable'.

Type '"Rules"' is not assignable to type 'PreconditionEntryResolvable'. src/preconditions/Rules.ts: ```js export class RulesPrecondition extends Precondition {...

Custom Hook before a Piece being called/run

Is there something like beforeRun hook where we can register custom function to be called. I'd imagine something like a middleware before the piece messageRun or chatInputRun being called. What I'm trying to do is to add a logger that is able to read the piece name and it's message/content. Currently doing it by adding the code right on the beginning of the run function, in which is not efficient and easy to forget.