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

Bot doesn't trigger error events

I want to add error reporting to my bot and to test it I added two errors to my bot: a manually thrown one (calling throw new Error('You've got an error!');) and an E500 (in this case checking a property of a null object) I've added the ```...
Solution:
define bad commands. At any rate, Sapphire has its own error handlers. Check the Events constant we export. Events.ChatInputCommandError Events.ContextMenuCommandError Events.MessageCommandError and more...

Default guildId for all application commands

Is it possible to set a default guildId for all application commands?

Max Paginated Embeds

What is the max embeds for the Pagination Utility?
Solution:
10 embeds per message, 25 pages total. Limits are set by Discord API

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/@[email protected]/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/@[email protected]/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...