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

How can I find out what events there are, and what the args are?

For example, MentionPrefixOnly has run(message: msg), but what does anything else have? I have tried creating a listener for adding reactions but I am unsure if this is the proper syntax. sapphire generate listener generates a listener different than the default MentionPrefixOnly listener. I have tried scouring the documentation but I cannnot find anything relating to the arguments of run(). Thank you!...
Solution:
messageReactionAdd is a DiscordJS event so the payload is on https://discord.js.org/docs/packages/discord.js/14.14.1/Client:Class#messageReactionAdd

Unable to get piece's name with CommandStore#get when piece's enabled is false

When doing CommandStore#get with a piece that is not enabled, it returns undefined. But when getting the piece with its aliases, it returns the piece correctly. This issue doesn't effect pieces that is manually disabled
Solution:
that is correct. Pieces that are disabled get unloaded.

The precondition "SubcommandCooldown" is not available.

Hi, I have cooldowns configured on a subcommand like so, but running the command gives the title error.
Solution:
You need to register the plugin somewhere with import('@sapphire/plugin-subccommands/register') (mentioned in the readme)...

TypeError: Cannot read properties of undefined (reading 'options')

im not even sure what i did wrong lmao https://i.proxied.host/u/N7N6gq.png @ me when replying pls...
Solution:
yall not gonna believe it but I deleted node_modules and reinstalled them and it's working now Kek

Change select menu options to custom options for paginated messages

Hi, how do I change the options to, for example, "test1" & "test2" instead? I'm using @sapphire/discord.js-utilities for Paginated Messages, if that's useful....
Solution:
https://www.sapphirejs.dev/docs/Documentation/api-utilities/classes/sapphire_discord_js_utilities.PaginatedMessage#setselectmenuoptions The callback function paramater has a pageIndex as shown so you can detect it for each page and add the proper text....

Is it possible to set retries for a MessagePrompter (message strat)?

Title, and if it is possible, how? I did look through the docs and didn't find a clue.
Solution:
It is not, sorry.

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: ```ts 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:');...
Solution:
First of all there won't be duplicate entries. The entry will simply have both messageRun and chatInputRun Secondly, for slash commands you do not need a help command because you have description fields for the commands and options already Thirdly, you can take inspiration from @Skyra https://github.com/skyra-project/skyra/blob/main/src/commands/General/help.ts#L189-L206...

Subcommand Organization

I'm switching back to the sapphire subcommand plugin from kanames since it's not updated and I'm running into a minor issue I'm not sure how to solve. With the sapphire subcommand plugin all subcommands in a single top level subcommand are supposed to have the chatinputrun methods defined in the same file. This makes my subcommand files very long and hard to get to the code for individual commands. I've tried putting the logic for the commands in their own file, but then I get "Error [EMPTY_MODU...
Solution:
I'm not entirely sure if it'll work but I think you can prefix the files that have utility functions with a _ so they're not loaded as pieces. If that doesn't work then yes you'll have to put them outside the commands folder.

Create WebServer with Plugin API

Hello ! I read the doc for install a webserver in my bot. Here my code: ```js...
Solution:
OK, that's it. He didn't like port 8080...

LoaderStrategy: promises.opendir is being broken if using with @vercel/pkg library

Hey There! I'm trying to build the bot into signle executable but there is an issue When trying to load the listeners, commands etc It fails because of ```js node:internal/process/promises:288...
Solution:
You can change all your pieces to virtual pieces so no more filesystem calls are performed: https://www.sapphirejs.dev/docs/Guide/additional-information/registering-virtual-pieces

Template project (Issues setting up from scratch)

is there a skeleton sapphire project somewhere? I am having issues setting up even this https://www.sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire with typescript. something about node:31148) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. and TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\Documents\Git Projects\Lyra-Bot\src\index.ts when switching the index.js extension to .ts. I am using node 20.10.0. thank you!...
Solution:
There are several options 1. @sapphire/cli can generate a new start 2. Those are taken from https://github.com/sapphiredev/examples so you can also do it manually 3. There are many open source bots that you can look at:...

Argument of type 'Context' is not assignable to parameter of type 'LoaderContext

Hi, I am getting above error in various files when deploying on production after upgrading my ts-config from 4.00 to 5.00. I do not get it when building the docker image on my local machine. Any ideas how that discrepancy would happen?
Solution:
Use LoaderContext where you currently use Context. Wherever the error shows up. For further support show the errors and the code. Also:

Any tips for store data in the interaction ?

Hello What is the best way to store data through interactions? Today, I put everything in the customId of the interaction, but it is limited to 100 characters......

Error handling

Hello ! Is there anything native to Sapphire that allows error handling? I want to capture all the bot's unhandled errors and to be able to act on them....
Solution:
That error will land at chatInputRunError / contextMenuRunError / messageRunError which is the highest level catch all event for commands. NodeJS, or at least Discord bots, do not have some kind of error context that's a try/catch for everything. Errors for backend services are also different than frontend. For frontend you dont ever want to throw the user in an error state because they will see it and it disrupts their user experience, however, for backend errors they will end up in the logging at the worst and the application will remaining running...

Removing pagination buttons on last page

Hi there, what is the recommended way to remove the pagination buttons on the last page when using the paginator in sapphire djs utilities?
Solution:
at any rate, use setPageActions and set the index (second parameter) to the last page index then pass an empty array I think

Error when loading events

Hello ! I'm creating a Discord bot with Sapphire and when I create an event, I have this error : Error when loading '/home/desk/bot-sapphire/common/src/ticket/listeners/ready.js': Error: Dynamic require of "/home/desk/bot-sapphire/common/src/ticket/listeners/ready.js" is not supported...
Solution:
Ok I undertstand ... I don't use .mjs extension on my file ... But I don't understand here : https://github.com/sapphiredev/pieces/blob/main/src/lib/strategies/LoaderStrategy.ts#L73 How does it work ? If I use ESM, we should use import() instead of require(), no ?...

Command Preconditions

Is there a way to check what preconditions a command has applied?
Solution:
this.options.preconditions or replace this with however you got the Command instance @D24

error TS6053: File '@sapphire/ts-config' not found.

I'm trying to add jest tests to a project and I started to get this error. ``` Error: Jest: Failed to parse the TypeScript config file jest.config.ts TSError: тип Unable to compile TypeScript:...
No description

Slash commands are not being registered when using Bun

Hello, I'm having trouble running the framework with bun because the slash commands are not being registered. I created a new empty project with bun init and then installed discord.js and @sapphire/framework My index.ts file, which is the entrypoint, looks like this:...

What is the event name for when vanity gets updated?

i tried looking into guildUpdate but it's not there
Solution:
You could fetch the audit log in the guildUpdateEvent Or you could use the auditlog event...