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

Context Menu Commands Lowercase Name

Hello, I have noticed when creating a context menu command, despite me writing "Warn" as the command name in the code, it appears as "warn" on the actual context menu.
Solution:
Huh. I don't recall that we lowercase it internally. Anyway, you can just change this.name to "Warn"

.loadAll() blocks all shards?

Okay, I have finally isolated my problem which I've opened multiple questions about. The problem is that ```js await client.stores.get('commands').loadAll();...

Paginated message help

Hey, is there a way to change the items of the pagination message? Ideally with the PaginationFieldMessageEmbed. The use case is I want to build up an inventory for a RPG and want separate categories (to be selected using SelectMenu) At a given time, only one type of category would be shown.. Is there a way to swap out the old items and replace with brand new ones?

Plugin API - Origin

If you had to had to build the logic for the API to at least accept one other URL to the allowed origins, where would you start? I'm struggling to understand where the plugin API is setting things up. Edit: Just found PluginMiddleware in Headers. It should be this one right?...
Solution:
why do you want to allow 2 origins anyway? If you're referring to both localhost and your production URL, you're supposed to separate your development and production environments to begin with. Never test/develop in production. that said, yes you were on the right path of it being this middleware: https://github.com/sapphiredev/plugins/blob/main/packages/api/src/middlewares/headers.ts. As you can see you can just set clientOptions.api.origin to * or whatever you want....

How to Register a Discord Slash Command via Sapphire without creating a command file

First of All, I am doing this for a private bot.. so i don't care about other people exploiting the bot if the bot is restarted will sapphire load the command registered without creating a file automatically? if not what should be my other approach ...
Solution:
Looks like you may be looking for https://www.sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/advanced/registering-application-commands-outside-a-command and you simply leave out the registry part in the command file itself. You can also load actual commands in memory by simply setting them in the command store map (container.client.stores.get('commands').set('name', data)). See also https://github.com/sapphiredev/pieces/blob/375896b05897da0fbddbfa7a416c4c7f17445bc1/src/lib/structures/Store.ts#L103 for how we normally load files, you'll want to mimick this for in memory loading. Also you're safe to start loading commands in the ready listener.... Slightly before that if you really must by using the plugin hooks but the difference is so minimal that it's probably not worth the effort....

How can i use the ephemeral to PaginatedMessage?

Example code typescript: ```ts const myPaginatedMessage = new PaginatedMessage(); // Once you have an instance of PaginatedMessage you can call various methods on it to add pages to it. // For more details see each method's documentation....
Solution:
first deferReply ephermeral then run run method

Somehow I got in an infinite loop

I have this old code that worked well for a long time, but somehow it now gets stuck in an infinite loop: ```js let cmdsrelo = await botclient.stores.get("commands") console.log("gotten cmdsrelo on shard " + botclient.shard.ids[0])...

Bot no longer runs after conversion to Typescript

I have converted by bot to typescript from ESM JS, now it logs in successfully but then none of the commands (message and slash) execute, console output:
[INFO] ApplicationCommandRegistries: Initializing...
[INFO] ApplicationCommandRegistries: Took 201ms to initialize.
[INFO] ApplicationCommandRegistries: Initializing...
[INFO] ApplicationCommandRegistries: Took 201ms to initialize.
...
Solution:
change What's your "main" property in package.json? src/index.ts to dist/index.js

Preconditions not running

I'm new to sapphire, but I can't seem to figure out preconditions. The code i have in /listeners/commands/commandDenied ```js const { Listener } = require("@sapphire/framework") ...

Does .gitignore just not work?

I added the env file to my .gitignore and it literally does nothing, vscode still keeps trying to stage it and it can still be commited
Solution:
If it was included in a previous commit, you must remove it from the index, this should do the trick: git rm --cached <file>. More info at https://stackoverflow.com/questions/1274057/how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore

Trying to use Buttons with sapphire

The inferred type of 'parse' cannot be named without a reference to '.pnpm/@sapphire+result@2.6.4/node_modules/@sapphire/result'. This is likely not portable. A type annotation is necessary.
The inferred type of 'parse' cannot be named without a reference to '.pnpm/@sapphire+result@2.6.4/node_modules/@sapphire/result'. This is likely not portable. A type annotation is necessary.
I created a Button increation handler using sapphire cli but for some reason they might be using old types?...

modal submission not triggering listener

i have made a modal submit listener. but for only one of my modals it just refuses to trigger the listener and causes an error. anybody know why this might happen
Solution:
i figured it out. it was because my parser defaulted to returning this.none(). which im guessing is telling the client that the modal is invalid. This could've been documented a bit better.

Container augmentation no longer working

I'm working on updating my dependencies to work with TS5 and my module augmentation specifically for container is no longer working. Augmentation of stuff in @sapphire/framework like DetailedDescriptionCommandObject is still working just fine. Here is the file where I'm doing the augmentation: https://github.com/BenSegal855/Steve-V3/blob/dev/src/lib/augments.ts Here is my current local package.json: https://pastebin.com/63NJ74FJ...
Solution:
things to try: - remove this line: https://github.com/BenSegal855/Steve-V3/blob/f1be38658a9df71668b4dd1503dfb969f12c7d8e/.vscode/settings.json#L6 - remove node_modules & reinstall - reload vscode - make sure you do not have Ts 4 somewhere in your transient dependencies (yarn why typescript)...

Snowflake limit

What's this limitation 4095 in @sapphire/snowflake?

Custom Events not Creating Listeners

I'm having issues using Sapphire with custom events. For example, I have an event for when a member subscribes to a role: ```ts import { ApplyOptions } from '@sapphire/decorators'; import { container, Listener } from '@sapphire/framework'; import { type GuildMember } from 'discord.js';...
Solution:
https://github.com/skyra-project/skyra/blob/main/src/listeners/guilds/members/notMutedMemberAddInitialRole.ts https://github.com/skyra-project/skyra/blob/main/src/listeners/guilds/members/guildMemberAdd.ts#L15 Custom events should work just fine. Make sure your emits are actually called and you do not have duplicate file names. By default the name of the file is used as the piece name, and the piece name has to be unique because we use a Map which has unique keys https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map...

Ignoring Precondition Failures

I'm working on a precondition that I wanna ignore on the ChatInputCommandDenied listener. The documentation suggests to a add information on the context in the Precondition ```ts export class MyDummyPreconditions extends Precondition {...
Solution:
Only button ones can update a message with the same content and be fine

Select menu interaction handler not working

I have a select menu interaction handler which never actually get the interaction, I added a console log in the parse function and it wasn't triggered either, ideas? File: https://github.com/oriel-beck/application-bot/blob/v4/src/interaction-handlers/apply/select.ts...

Dms not being read by Event.messageCreate in listener.

So after an hour of research and checking the guide every 10 minutes, I am fairly confused on why my bot is not reading DMs. This is to implement a ModMail system to my existing bot. The full repo is here on the major development branch: https://github.com/MiekoHikari/VTA-Discord-Bot/tree/major-development Im sure I put in the right bitfield intents and I used the sapphire CLI to generate a ts template for me! I'm sure its a silly mistake somewhere but can't find it V - V...
Solution:
For DMs you need to enable message partials. https://discordjs.guide/popular-topics/faq.html#enabling-partials FYI this is not a sapphire thing, the same would count if you just used Discordjs raw. Sapphire doesn't do anything special like forwarding or filtering events, we only bind them to the client, that's it....

Paginated message exceeding 25 pages

(node:1) [PAGINATED_MESSAGE_EXCEEDED_MAXIMUM_AMOUNT_OF_PAGES] PaginatedMessageExceededMessagePageAmount: Maximum amount of pages exceeded for PaginatedMessage. Please check your instance of PaginatedMessage and ensure that you do not exceed 25 pages total.
If you do need more than 25 pages you can extend the class and overwrite the actions in the constructor.
(node:1) [PAGINATED_MESSAGE_EXCEEDED_MAXIMUM_AMOUNT_OF_PAGES] PaginatedMessageExceededMessagePageAmount: Maximum amount of pages exceeded for PaginatedMessage. Please check your instance of PaginatedMessage and ensure that you do not exceed 25 pages total.
If you do need more than 25 pages you can extend the class and overwrite the actions in the constructor.
Why can't paginated messages go more than 25 pages, and how do I do what the last line is telling me to do?...
Solution:
Nevermind, figured it out. Paginated messages can't go more than 25 pages due to the select menu for the pages (which is limited to 25 choices)

Is it possible to run the same bot multiple times and have them each independently handle commands?

I was wondering if I can just run multiple instances of the same bot and have them handle commands on a per channel basis. Each instance of the bot would have it's own config that tells it what channel it can respond to commands in. I was able to achieve this in discord-akairo (old discord framework) with message commands, but I don't know if this would work with interaction commands....
Solution:
Nevermind. Everything worked perfectly from the start. My own filter feature was making me think no messages were being sent to the second instance's channel. I guess there was an influx of messages all at once in the first instance's channel which made me think it was both instance's messages.