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

Seemingly Random Command Registration Failures

Hello there, I created a basic command, however whenever the bot refreshes, the command registration almost always fails. And this most recent time, the command registered, and then after a refresh, it failed to register again. Error: ``` 2023-12-07 22:42:52 - ERROR - ApplicationCommandRegistries(BulkOverwrite) Failed to overwrite global application commands DiscordAPIError[50035]: Invalid Form Body...
Solution:
Ah issue was from an old issue in an old file that was still in the built files, so was still running

Is that possible to have multiple routes in the same route class?

Something like: ```ts @ApplyOptions<RouteOptions>({ route: 'users' }) export class UsersRoute extends Route { // GET in /users...
Solution:
it is not

Command not being registered

Hello, I'm currently following the guide for Sapphire and here's the first error, I can't seem to be able to register a command, that must be the dumbest mistake you've ever seen but after going throught the code a few times I can't get the error... Any idea ? https://pastebin.com/XSEepVsP ...
Solution:
OK so basically I added a console.log to the Register method and now it works, I'm guessing it was a random starting error and that refreshed the process or something 🤷‍♂️

Property does not exist on type 'Container'

i'm trying to use DI in typescript like on this page https://www.sapphirejs.dev/docs/Guide/additional-information/using-and-extending-container and i can't get it to work. my code is ```ts export class MyClient extends SapphireClient { public constructor() { super(...optionsandstuff); }...
Solution:
Start by updating your dependencies. If anything framework 4.8.2 is bugged (as opposed to 4.8.5) but you should be able to just update to v5. Also make sure you do not have @sapphire/pieces in your dependencies, let it be installed as a transitive dependency.

Sapphire eslint-config

So I updated eslint-config and all plugins to their latest versions, eslint-config is at 5.0.3 and now I get this so I am wondering did the syntax to extend change? ```...
Solution:
restart your IDE?
No description

Translate runIn error message

Since runIn pre condition do not return the identifier of precondition that failed, is there a way to translate the message of the error or should I just don't use the runIn: CommandOptionsRunTypeEnum.GuildAny and only use preconditions: ['GuildOnly']?

Type issues with .addChoices()

I am attempting to add choices to a string option, and this error is a little confusing. See what I mean: ```ts option.setName("type").setDescription("Choose whether to snipe an entire message or a message edit.") .addChoices([...
Solution:
addChoices has a spread syntax for the array type, so remove the square brackets and it will work.

Sapphire registering applications bug

So I updated sapphire to the latest version and when i start my bot the ApplicationCommand registering keeps thinking that there is differences found in every single command (Provided few screenshots)
Solution:
@sapphire/framework@pr-701
No description

Error when creating a modal

Can someone help me figure the cause of this error, heres my code below and the error. Code: ```js const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework');...
Solution:
i used createMessageComponentCollector() instead of doing it all in the button interaction handler

Linter errors in command options after upgrade

Hey there, After upgrading to the freshest Sapphire and Discord.js versions I've got error in every command where I parse the options. For example: ```...
Solution:
I had to reinstall the IDE and now it seems to work

augments

hello, when augmenting the @sapphire/pieces to edit the container, when i use pnpm i am required to install '@sapphire/pieces' package or augments for @sapphire/pieces do not work

Tooling question

If I want to like add eslint-plugin should I add both eslint and eslint-plugin and then override the rule in package.json, ```ts "rules": { "node/no-process-env": "error" },...
Solution:
Yes, unless by other way you meant using an .eslintrc file. You also don’t have to use sapphire’s config if you don’t want to. https://archive.eslint.org/docs/7.0.0/user-guide/configuring#:~:text=There%20are%20two%20primary%20ways%20to%20configure%20ESLint%3A,entire%20directory%20and%20all%20of%20its%20subdirectories.%20

[ERROR] Encountered error on event listener "moderationLog"

Full Error: https://pastebin.com/GnkxtJqe moderationLog Listener: https://pastebin.com/DLgksCHN...
Solution:
moreover, looking at the error stack at ModerationLogListener.run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\moderationLog.js:19:8) the error appears here, maybe your getPunishmentTitle or getAutomodPunishmentTitle is returning null/undefined instead of a string, better fix that...

Fetch reply from a command to button interaction

How can i fetch a reply from x command so i can edit the reply in y button interaction
Solution:
the interaction passed through the interaction-handler is a ButtonInteraction so that should help https://discordjs.dev/docs/packages/discord.js/14.14.1/ButtonInteraction:Class#message...

Is there a way to use Sapphire to reset previously registered slash commands?

So, I've got a bot I'm working on that uses Sapphire and recently, just as an example, I generated a unban.ts slash command while I had npm run:watch running (so it registered the command with the bot). I then moved the unban.ts file to the Moderation folder I created for commands like this one, and now I need the previous unban command to become unregistered. Is there any way I could have Sapphire automatically unregister slash commands created like this one upon finding that the files for the...
Solution:
Then it would probably be because TypeScript does not delete old files from the dist folder when you move them in the src folder. Clean your dist folder and rebuild.

Arguments

The channel built-in argument will detect any channel? (Including Text Channels, Voice Channels, Threads, etc)?

Decorators issue

Never used decorators, so I can't tell the reason why this is an issue
Solution:
I solved it by adding "target": "ES2016" in tsconfig.json
No description

Paginination limitation when not using select menus

I have the following error being presented to me
(node:1484241) [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.
and this is my current code giving the error: ```ts...
Solution:
Extend the class and override the addPage method. Never forget the basic principles of object oriented programming. You can achieve a lot with simple class extension....

Run bot without building to js and use ts-node or other alternatives instead.

Is there a way to achieve the title? Currently I need to build and then run the js file using the command:
npm run build && npm run start
npm run build && npm run start
...
Solution:
If you want to test the bot, then tsc-watch is good. Or you can remove typescript & code directly in js Or you can use bun runtime to start your typescript based bot directly (you will need to refactor your code so that it runs on bun)...

Unregister Old Application Sub Commands from the subcommands plugin

Some old commands i have made still appear in the autofill when typing a application command, how would i get rid of those?
Solution:
If they are still registered either use bulk overwrite by sapphire, use the discordjs methods to unregister, or use https://slash-commands-gui.androz2091.fr