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

Preconditions in Interaction Handler

Is it possible to use preconditions in the interaction handler? I was hoping to have preconditions work with my buttons as well ๐Ÿ˜
Solution:
It is not, however, remember that preconditions are basically just glorified if else checks.

Difference with dev and prod > The application now has 0 global commands

Not sure what I'm missing here. When I run my dev command nodemon src/Bot.ts - everything works as expected, the bot is online and responsive, with 4 global commands. When I run my build command tsc - the build is successful...
Solution:
See the first big red block at the getting started guide https://sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire

text command triggered by mentioning bot (no command name)

I want to trigger a text command when the user mentions the bot, but with no command name. what is the best way to implement this?
Solution:
Add a listener called mentionPrefixOnly

I want to make a system about module command

I'm stuck right now, I only want 3 commands to be able to deploy globally, and in that there is 1 command to edit the modules, which will contain the commands. What I want to do is that the command to edit the module can automatically register a separate slash for that server. Can you help me?

Slash command autocompletion dynamic input options

I'm looking around the DiscordJS documentation and SapphireJS docs to see if there might be a way to add the ability to, essentially, have a user type a slash command like: /play input:<search terms> And when they are inputting the search terms, have options populate above like how some music bots do. ...
Solution:
Command#autocompleteRun can be async, which means you can execute a fetch HTTP request to retrieve the results and show them back to the user.

string-store not finding identifiers other than first in Schema on deserialize typescript

I am working on some new code for my bot and using the string-store utility. I've gone through https://discord.com/channels/737141877803057244/1303945790057746452 and https://discord.com/channels/737141877803057244/1303856829461168138 and have been able to get the system working with the steps in there. My schema is: ```ts import { Schema, SchemaStore, t } from '@sapphire/string-store';...
Solution:
Your store has 2 schemas, so when it deserializes a buffer, it can be one of the two. Compare the id or cast the value to the correct type to fix this.

Why my listener doesn't work?

Hello, i am trying to make a uptime checker thing. I'm currently just using a ready listener for test. main.ts ```ts import 'dotenv/config';...
Solution:
1. Which version of @sapphire/framework are you using? 2. What's your file/folder structure? 3. Did you use the CLI to generate your bot? 4. What's your main (CJS) or module (ESM) property in package.json 5. Are you using TypeScript? And if so, how are you compiling and running your code? That is to say, what are your build and startup scripts?...

my guild related listeners arent firing but my client ones are

pretty much just the title
Solution:
i just remembered that messageReactionAdd won't fire on uncached messages, unless u were to enable partials

Unexspected end of JSON input

Hey guys, I recently updated from API Plugin v6.1.1 to v7.0.3 and got into trouble with the new handling of request body. I try to extract the body of my request with const body = await request.readBodyJson();...
Solution:
You shouldn't read the body twice ๐Ÿ˜…

Updating paginated message pages while the handler is running

I'm trying to make a paginated message that can be updated after its creation. My command currently: 1. Responds with the paginated message with data from the database 2. Fetches new data from an API in the background...

JS Example has error with loading routes

I've downloaded the JS example from here: https://github.com/sapphiredev/examples/tree/main/examples/with-javascript The bot runs fine apart from a few issues with loading the routes ``` Error when loading 'C:\Users\Jacob\Downloads\sapph\src\routes\hello-world.js': TypeError: Cannot read properties of undefined (reading 'GET')...
Solution:
The second is because you need to install a build toolchain, see https://github.com/nodejs/node-gyp#on-windows The first... is because the code wasn't updated to Sapphire Plugin v7. If you don't need REST api plugin, just delete those files for now. If you do, then refer to the breaking changes, also we'd very much appreciate a PR โค๏ธ https://github.com/sapphiredev/plugins/blob/main/packages/api/CHANGELOG.md#sapphireplugin-api700---2024-11-02...

Precondition not triggering "chatInputCommandDenied"

I have setup the following precondition:
Solution:
Ah I also see where you're going wrong here. Yes you land on the breakpoint for this.error, however because you're using Array#forEach which accepts a callback function that returns void you're not actually returning this.error for the function chatInputRun but rather for the anonymous arrow function that is provided to Array#forEach. You can solve this by using for...of instead....

Sapphire keeps taking me in circles! Can't access my Dashboard.

Hello! I just added the Sapphire bot to my server yesterday, and I wanted to make a few edits. I headed over to the Sapphire Dashboard on my browser to log in, but I just keep getting taken in circles. I can no longer access my Dashboard. I've tried clearing my cache/cookies for the site. I've also tried logging in on another device with no luck. I'm stuck on the login page that says "You're currently logged in as _" It shows all of the servers that I operate underneath (photo attached). When I click on the server that I'd like to adjust, the page "refreshes" but then stays where it is. So frustrating! Any help would be greatly appreciated!...
Solution:
You seem to be asking a question related to the "Sapphire" bot, not the "Sapphire" framework. These are separate projects that share the same name but have no relation to one another. You may instead be looking for https://discord.gg/EXqShySz8h...
No description

multiple idHints for multiple servers

hi, quick question. is this okay if i deploy a slash command in two server, not as global, and have their two idHints be put in the code? ill attach screenshot, just making sure it's all good
Solution:
Yeah
No description

Serializing string-store result inside another schema

I'm trying to re-work customId serialization in my framework, and my plan is to use string-store for this. One of the features in my framework is that you can make customIds that refer to commands, kind of like this: ```ts class MyCommand extends Command { public async execute(i: ChatInputInteraction, meta: Metadata) { const bot = meta.getBot();...
Solution:
I don't think it's a good idea to let users write or paste raw string-store data, for starters, it produces strings created by abusing the underlying UTF16 standard, which can lead to very confusing characters... and invisible ones, among which NULL (\0), which is often the delimiter character at the end of a string in C (see strlen()), which... Windows, Linux, and perhaps MacOS as well rely on. That being said, if you convert the binary to base64, then you'll be able to share it in plain text on Discord more nicely. serialize returns an instance of UnalignedUint16Array after all, with some code you can convert it to base64, this should work:
const data = store.serialize(/** data */);
const base64 = Buffer.from(data.toArray().buffer).toString('base64');
const data = store.serialize(/** data */);
const base64 = Buffer.from(data.toArray().buffer).toString('base64');
...

Random date generator

Hello! I know nothing about how to code. What im trying to do is make the bot create a random date when i use like !randomdate or something. Im trying to use chatgpt to help me make the code but i just cant understand it and it wont work. im trying to insert it into the "raw" aspect of message templates
Solution:
Before you make a Discord Bot, you should have a good understanding of JavaScript. This means you should have a basic understanding of the following topics: - Read and understand docs - Debug code - Syntax...

fallback

How i can add a fall back globaly for all RequiresGuildContext ..
Solution:
It is not possible. RequiresGuildContext is a decorator and decorators inherently will always only work on what they decorate. You can copy the code and add it to your own repo where you then provide a default function for fallback. https://github.com/sapphiredev/utilities/blob/bc456c311f273efcb8150d4e33d614c9889c3ed7/packages/decorators/src/djs-decorators.ts#L190-L192...

Constantly getting "The application did not respond"

Hello, I am constantly getting the "The application did not respond" message. Not matter what I try to achieve the only thing that is fast enough to execute is a simple await interaction.reply('bla bla'). Anytime I try to do something from bulkDelete to sending embeds or creating buttons, I get the thing. Is there anything to try and debug that? Is it possible that my computer is too slow for developing a bot (lmao, it is not that slow though). Obviously defering doesn't do a thing. At first I thought my code was wrong but sometimes it works, sometimes it doesn't... One thing remains, this damn message telling me it didn't respond. Maybe there is a problem with how Sapphire handles my commands right now, found somewhere that a command handler could mess things up and take too long to load up the commands so in the meantime, no response......

@sapphire/type does not work with Bun

Hello! I was trying to get my Sapphire application up and running on my server, however I was greeted with this error: ``` silver-wolf | $ bun src/index.ts silver-wolf | Error when loading '/usr/src/app/src/commands/utils/eval.ts': 17 | var publicField = (obj, key, value) => defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); silver-wolf | 18 | var getFilename = /* @PURE */ __name(() => fileURLToPath(import.meta.url), "getFilename");...
Solution:
Adding to this, @sapphire/type doesn't use Node.js' internals, it uses v8.h (see source code). Because Bun is built on JavaScriptCore (JSC) and not V8, we can't make the internal inspecting part available for Bun even with a Rust rewrite.