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

Sapphire-like Listeners for other Emitters, such as ShardManager?

Probably a stupid question, but I've looked and haven't found any. Does Sapphire support listeners for other emitters? For example, if I want to listen for the shardCreate event of ShardManager. Sapphire makes event handling so simple, so I figured I'd hope that there is, instead of going manual....

scheduled tasks plugin compatibility

It is possible to use upstash redis server with the plugin?
Solution:
We use Bullmq so best check out the exact status there. For example https://github.com/upstash/issues/issues/18

it's bugging for me

Cannot use import statement outside of a module

Event before interaction handlers are ran

There are ChatInputCommandRun and ContextMenuCommandRun events, which are emitted before the run method. Is there anything similar for interaction handlers which is emitted after parse but before run?
Solution:

How do I handle this UserError?

I've been fiddling around with the subcommands plugin and I see that it throws an error ("No subcommand was matched with the provided arguments.") every time there is not a default defined and it doesnt match with a command. I am not trying to add a default, but I am trying to handle this error by adding a response message, e.g. "Did you mean to execute ...". I have tried using a listener to listen to Events.Error but it never gets fired....

How to transform array with shapeshift using default values?

I have an array which I'm trying to validate with shapeshift: ``ts const bans = JSON.parse(data); const defaultReason = Imported by ${interaction.user.username} from ${link}`;...
Solution:
Solution: ```ts const banList = s .array(s.string)...

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...